-
Notifications
You must be signed in to change notification settings - Fork 7
Usage
The binding stores the mapping between an interface and a concrete type in InjectABL. Bindings allow us to easily change the objects being injected, to provide the necessary parameters for injection, and to specify conditions under which the bindings are valid.
Modules are collections of bindings that are loaded into the kernel; multiple modules can (and will typically) be loaded into a single kernel. This allows an application to keep its bindings at an appropriate level of granularity (ie. there aren't accounting bindings mixed together with the infrastructure bindings).
Modules typically inherit from the abstract OpenEdge.InjectABL.Binding.Modules.InjectionModule class, which implements OpenEdge.InjectABL.Binding.Modules.IInjectionModule. The individual bindings are created (destroyed) when the module is loaded (unloaded) into the kernel.
InjectABL supports the concept of a ModuleLoader which can discover the modules in the application: this may work on some kind of name pattern (e.g. "*Module.cls").
Note that there's nothing precluding the storage of bindings in JSON, XML or some other data store, such as a database table.
The syntax for binding is defined in the OpenEdge.InjectABL.Binding.IBindingSyntax interface, and can be described as below. <type> below refers to an instance of Progress.Lang.Class. A type is specified since it is the kernel that creates the instance from this type. The binding is not responsible for instantiating the implementation (that's the kernel's job).
The type passed in to the Bind() method is referred to a service in the InjectABL module; this should not be confused with the notion of a service as in SOA.
Bind(<type>) /* [required] service/interface or concrete class */
:ToSelf()|To(<type>) /* [required] concrete class type. ToSelf requires that the binding above be to a concrete type */
:Using(<type>) /* provider type */
:InSingletonScope()|InTransientScope()|InAgentScope()|InScope(<type>, <enum>) /* The lifecycle scope of the object. The InScope() allows for custom scope */
:OnClientSession()|OnWebSession()|OnServerSession() /* To which session type this binding applies */
:Named(<char name>) /* An instance name for the object */
:WithConstructorArgument(<parameter>) /* One or more constructor arguments to use. These can be ABL primitives, types or objects */
:WithPropertyValue(<property name>, <parameter>) /* One or more properties to set. These can be ABL primitives, types or objects */
:WithMethodValue(<method name>, <parameter>) /* One or more method arguments for one or more methods. These can be ABL primitives, types or objects */
:When:<condition> /* One or more conditions conforming to IConditionSyntax */