Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The ViewMap
provides auto DI for your views. Like the mediator map, it listens for
Event.ADDED_TO_STAGE on the context view,
and then checks to see whether the view that has been added has been
mapped in the context using:
viewMap.mapType(SomeView);
Alternatively, you can request injection on all the views in a package using the package name:
viewMap.mapPackage('com.example.view.characters');
When the view map finds that a view that has been added to the stage is one of the mapped types, or comes from one of the mapped packages, it passes this view to the injector to have its dependencies fulfilled.
In reality, injection into your views is problematic, and we don’t recommend that you take this approach unless you have a very specific purpose for it. Generally, the kinds of applications—usually games—that would benefit from view injection are also the applications where performance is most important, and there are much more performant ways to pass dependencies to view classes—for example by instantiating them via a factory.