Packagepotomac.inject
Classpublic class Injector
InheritanceInjector Inheritance Object

Injector is responsible for creating new classes and injecting dependencies into them.

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:

boundToFully qualified interface or class name that becomes the binding's front class.
implementedByFully qualified class name of the implementation class. If not specified, the class where the [Injectable] was declared is assumed.
namedA unique string which differentiates this binding from others bound to the same type.
providedByA fully qualified class that implements IProvider. Providers allow programmatic control of injection class creation.
singletonTrue/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.



Public Methods
 MethodDefined By
  
Injector(bundleService:IBundleService)
Creates a new injector.
Injector
  
bind(clazz:Class):INamer
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
  
getInstanceOfExtension(extension:Extension, listener:Function = null):InjectionRequest
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
Constructor Detail
Injector()Constructor
public function Injector(bundleService:IBundleService)

Creates a new injector.

Parameters
bundleService:IBundleService — The main Potomac bundle service which the Injector will use to load bundles as necessary.
Method Detail
bind()method
public function bind(clazz:Class):INamer

Starts 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.

Returns
INamer — an INamer allowing further creation of the binding.

Example
The following code sets a binding on IInterface named "myName" to IImplementation as a singleton:
 
         myInjector.bind(IInterface).named("myName").toClass(IImplementation).asSingleton(); 
         
getInstance()method 
public function getInstance(className:String, named:String = null, listener:Function = null):InjectionRequest

Creates 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.

Returns
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):Object

Creates 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.

Returns
Object — An instance of the injection binding.
getInstanceOfExtension()method 
public function getInstanceOfExtension(extension:Extension, listener:Function = null):InjectionRequest

Creates 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.

Returns
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):void

Injects dependencies into the given object.

Parameters

object:Object