Dependency injection for GUI components
Hi all,
we have been using the springframework for Java for a long time now. I wouldn't call me an expert but i have some detailed knowledge especially when it comes to the web and mvc part.
For some recent projects and developments we are using the great Flex for building RIA-Applications.
What i like most about it is its intuitive MXML syntax which lets you create a complex UI in a very simple way.
To come to my question: I have a problem with understanding how an ApplicationContext based app with lots of standalone objects and a gui app with lots of nested components can be combined.
To provide a simple example of what i am facing right now i give you:
1. The Gui
1.a "MainApp"
Code:
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<local:NewsComponent />
<local:UsersComponent />
</mx:Application>
1.b "NewsComponent"
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<local:DataManager id="dataManager" />
<mx:DataGrid dataProvider="{dataManager.news}" />
</mx:Panel>
1.c "UsersComponent"
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<local:DataManager id="dataManager" />
<mx:DataGrid dataProvider="{dataManager.users}" />
</mx:Panel>
2. The "DataManger"
Code:
package
{
public class DataManager
{
private var news:ArrayCollection; // assume getter and setter
private var users:ArrayCollection; // assume getter and setter
}
}
3. The ApplicationContext definition
Code:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.pranaframework.org/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pranaframework.org/objects http://www.pranaframework.org/schema/objects/prana-objects-0.6.xsd">
<object id="dataManager" class="DataManager" />
<object id="usersComponent" class="UsersComponent">
<property name="dataManager" ref="dataManager" />
</object>
<object id="newsComponent" class="NewsComponent">
<property name="dataManager" ref="dataManager" />
</object>
</objects>
Now here is my challange: (if it really is ;))
Where and when do i create and load the application context?
Can i stick to that wonderful MXML Syntax and create guis with nested components that are objects of the app-context?