InjectionAutomatic InjectionIn order to automatically inject values into a variable 3 things need to happen. - The variable to inject must be public
- The variable to inject needs to be marked for injection with [Inject('injectorId')]
- The class must be introspected by Mainline
- ActionSctipt Project - In the constructor / initializer Mainline.introspect(this)
- Flex / Air Project - In the constructor addEventListener(FlexEvent.preinitialize,Mainline.inject)
example package com.mydomain.myapp
{
import com.tylerbeck.mainline.Mainline;
public class MyClass
{
[Inject('injectorId')]
public var myVar:Object;
public function MyClass( )
{
super();
Mainline.introspect( this );
}
}
}Programmatic InjectionMainline also allows you to get the contents of an injector manually. To do this you can use the following syntax: myVar = Mainline.getInjectorValue('injectorId')
|
Why the requirement for an 'injectorId'? Surely a lot of the time Inject? why be good enough?