Static Bindings in Services pattern
An Erlang function defined as a service property can be referenced by any operation on that service. This way a function can be used by multiple operations. You can also bind functions to variables declared on the operation level.
In the example in Table 1,
svc_expr
is used to produce new field sets by assigning new values to a
field, this time via static binding.
Example | Description |
---|---|
<mix name="Mix"> <service name="Expr" provision="expr"> <prop name="expr.src" content-type="text/x-erlang"><![CDATA[ IncrFun = fun(N) -> N + 1 end. ]]></prop> </service> <consume name="Increment" service="Expr" fields="value"> <prop name="expr.src" content-type="text/x-erlang"><![CDATA[ NewValue = IncrFun( get( "value")), put( "value", NewValue), "Ok". ]]></prop> <reply name="Ok" fields="value"/> </consume> </mix> |
The expr.src property of the service binds a function to the variable
IncrFun .This function can now be referenced in any operations
on this service, such as the Note: There
is no need to declare static bindings in the XML markup. They are automatic, and
all variables bound in the service expressions list are available to operations on
that service.
Note: Do not manually type the
<![CDATA...]]> delimiters. The Editor
automatically renders text content as XML CDATA sections. |