Dependency Injection
Hello,
I would like to be able to create an auto dependency injection system in flash. I am not completely sure what is the best way to handle this in flash. My first thought is having custom meta tags:
[Singleton]
class TheSingleton()
{
public DoSomething() {}
}
class TheNewObjec()
{
public DoSomething() {}
}
class MyObject()
{
[Inject]
public MyObject(TheSingleton theSingleton, TheNewObject theObject )
{
theSingleton.DoSomething();
theObject .DoSomething();
}
}
Instanciate(obj:*)
{
dependencies = obj.getDependencies();
for each ( dep in dependencies )
{
if ( dep.metaTag("Singleton") == true )
{
return _singletons[dep];
}
else
{
return new dep;
}
}
}
}
MyObject obj = Instanciate(MyObject);
Does this seem like the best approach?
Thanks
