Hi,
In spring actionscript, how's it is supposed for the whole application to lookup the ApplicationContext? Is it supposed to passing around through singleton? Any suggestions?
Dan
Hi,
In spring actionscript, how's it is supposed for the whole application to lookup the ApplicationContext? Is it supposed to passing around through singleton? Any suggestions?
Dan
Hi,
if you are talking about classes that have an object definition in the application context, you can let them implement the IApplicationContextAware interface.
For all other components not defined in the application context, you could indeed create a singleton that contains the application context, although I would not encourage you to do so.
regards,
Christophe
Hi,
Thanks so much for the response!
so, is there better suggestion other then the singleton.?
Dan
You can autowire/inject dependencies into view components and other objects defined in the application context. That way is preferred instead of working with dependency lookup where you just reference the container globally.
In general, try to use dependency injection as much as possible.
You can also post specific implementation questions if you have any.
Good luck!
If you want a 'surrogate' singleton for the application context you can always subclass Application and add a property to it to which you assign the FlexXMLApplicationContext.
Something like:
Whenever you need a reference to it in your app just look it up like this:Code:public class MyApplication extends Application { public var applicationContext:FlexXMLApplicationContext; }
That way you're not stuck with a 'real' singleton but you still have access to the main context should you need to.Code:MyApplication(Application.application).applicationContext;
cheers,
Roland