| Package | potomac.inject |
| Class | public class Injector |
| Inheritance | Injector Object |
Developers may use [Inject] to trigger injection on classes created through the Injector. The inject tag may include attribute names that match the argument or variable names to associate the arguments with named bindings. For example:
[Inject(field1="green")]
public var field1:IInterface;
[Inject(arg1="red",arg3="blue")]
public function injectHere(arg1:IInterface,arg2:IInterface,arg3:IInterface):void
{
...
Injection bindings can be created declaratively through [Injectable] or programmatically through bind(). The injectable tag supports parameters to build out injection rules. The attributes are:
| boundTo | Fully qualified interface or class name that becomes the binding's front class. |
| implementedBy | Fully qualified class name of the implementation class. If not specified, the class where the [Injectable] was declared is assumed. |
| named | A unique string which differentiates this binding from others bound to the same type. |
| providedBy | A fully qualified class that implements IProvider. Providers allow programmatic control of injection class creation. |
| singleton | True/false. If true the injector will only create one implementation instance for this binding. |
Examples:
[Injectable(boundTo="package.IInterface",named="green",providedBy="package.MyProvider",singleton="true")]
public class InterfaceImpl {
...
The primary Potomac injector is available for injection. It is bound directly to Injector.
| Method | Defined By | ||
|---|---|---|---|
Injector(bundleService:IBundleService)
Creates a new injector. | Injector | ||
Starts the creation of a injection binding to the given class. | Injector | ||
getInstance(className:String, named:String = null, listener:Function = null):InjectionRequest
Creates an instance (asynchronously) of the given injection rule. | Injector | ||
getInstanceImmediate(clazz:Class, named:String = null):Object
Creates an instance (synchronously) of the given injection binding. | Injector | ||
Creates an instance (asynchronously) of the class where the given extension was declared. | Injector | ||
injectInto(object:Object):void
Injects dependencies into the given object. | Injector | ||
| Injector | () | Constructor |
public function Injector(bundleService:IBundleService)Creates a new injector.
ParametersbundleService:IBundleService — The main Potomac bundle service which the Injector will use to load bundles as necessary.
|
| bind | () | method |
public function bind(clazz:Class):INamerStarts the creation of a injection binding to the given class. Use the returned INamer to continue to injection binding. Continue to use the returned object from subsequent calls to build the binding.
Parameters
clazz:Class — Class instance of a class or interface to create a binding for.
|
INamer — an INamer allowing further creation of the binding.
|
myInjector.bind(IInterface).named("myName").toClass(IImplementation).asSingleton();
| getInstance | () | method |
public function getInstance(className:String, named:String = null, listener:Function = null):InjectionRequestCreates an instance (asynchronously) of the given injection rule. If a listener function is given, the listener will be called automatically when the instance is created, otherwise the caller must add a listener to the returned InjectionRequest.
Parameters
className:String — Class name of the binding.
| |
named:String (default = null) — Name attribute of the binding.
| |
listener:Function (default = null) — Function to call when creation and injection are complete.
|
InjectionRequest — An injection request. If the caller supplied a listener function, the return value can be safely
ignored.
|
| getInstanceImmediate | () | method |
public function getInstanceImmediate(clazz:Class, named:String = null):ObjectCreates an instance (synchronously) of the given injection binding. This method should be used with caution as it assumes all necessary bundles are loaded to satisfy the injection requests.
Parameters
clazz:Class — Class of the injection binding.
| |
named:String (default = null) — Name attribute of the injection binding.
|
Object — An instance of the injection binding.
|
| getInstanceOfExtension | () | method |
public function getInstanceOfExtension(extension:Extension, listener:Function = null):InjectionRequestCreates an instance (asynchronously) of the class where the given extension was declared. If a listener function is given, the listener will be called automatically when the instance is created, otherwise the caller must add a listener to the returned InjectionRequest.
Parameters
extension:Extension — Extension whose declaring class should be created.
| |
listener:Function (default = null) — Listener fired when the instance is created.
|
InjectionRequest — An injection request. If the caller supplied a listener function, the return value can be safely
ignored.
|
| injectInto | () | method |
public function injectInto(object:Object):voidInjects dependencies into the given object.
Parameters
object:Object |