20 Jan in flex, mate

In my continued work with Flex and Mate I've come to understand the model Injectors system pretty well. Initially I struggled trying to understand a few things:

  • Where the model class is instantiated
  • How the injectors "find" the class to set its properties
  • How and when the injectors bind onto source properties

The answers are actually pretty simple once you understand the way that the InjectorTarget base class works. All models that require injection extend the InjectorTarget class. When the model is instantiated in your view, the InjectorTarget constructor adds a reference to itself into Mate's InjectorRegistry. If the model is instantiated 10 times, the InjectorRegistry contains references to all 10 models.
Now, in your event map you may have some code like this:
<actionLists:Injectors target="{TargetModel}">
<actions:PropertyInjector targetKey="someProperty" source="{SourceManager}" sourceKey="someProperty" />
</actionLists:Injectors>
This is executed once when the event map is instantiated (usually in your initial application file). This can be read in English as:
Whenever a TargetModel class is instantiated, copy the someProperty property value from SourceManager into the someProperty property of the TargetModel instance. Additionally, add bind event listeners to SourceManager.someProperty so when it changes in the future, copy the value again.
Note that the PropertyInjector will either create a new instance of SourceManager or pull one from the Mate cache if it has already been instantiated by another PropertyInjector.
So the simple answers to the above are...

  • Where the model class is instantiated - in your view
  • How the injectors "find" the class to set its properties - they exist in Mate's InjectorRegistry which is populated every time the model is instantiated by your view
  • How and when the injectors bind onto source properties - at the point the actionLists:Injectors code is called (which is when the event map is instantiated by your app)

Hope that helps!!

Comments

hello

Thanks, for the good articles...I am very intiresting..otogaz

All content © 2009-2011 Matthew Butt. All views expressed herein are my own and do not represent the views of my employer, AREA203 Digital.