5: Establishing Spring.NET configuration

Prerequisites: You should be familiar with the Spring.NET dependency injection. You should know how to write object creation syntax, you should know the object injection syntax (constructor injection, property injection …). Visit the http://www.springframework.net/ for more information.
We use the spring.net dependency injection to create and populate our objects. In this part 3 xml files are involved: the spring session xml file, the spring view xml file and the spring controller xml file. The spring session xml file contains xml declaration for creating all view datas.
Right click on the spring folder, choose Add menu and click New Item. Choose XML File and name the file spring-ContactManager_SESSIONS.xml. The listing 7 shows the contain of the file:

<?xml version="1.0" encoding="utf-8" ?>

<objects xmlns="http://www.springframework.net">

  <object id="Session" type="Koossery.MVCwin.Data.Session, Koossery.MVCwin">
    <property name="SessionData">
      <dictionary key-type="string" value-type="Koossery.MVCwin.Data.AbstractBaseData, Koossery.MVCwin">
        <entry key="ListViewData"> 
          <ref object="ListViewData" />
        </entry>
      </dictionary>
    </property>
  </object>

  <object id="ListViewData" type="ContactManager.data.viewdata.contact.ListViewData, ContactManager" />  
</objects>


We create the Session object and inject the dictionary SessionData with views data objects. All views data can then be accessible from views or actions by the GetSessionData() method.
The spring view file contains xml declaration for creating views. Adds an XML File named spring-ContactManager_VIEWS.xml in the spring folder. The following listing shows the contain of the spring file:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">

 <import resource="spring-ContactManager_SESSIONS.xml"/>
   <object id=" Koossery.xxx.xxx.BaseView"  type="Koossery.xxx.xxx.BaseView" abstract="true">
    
    <property name="Session">
      <ref object="Session"/>
    </property>
  </object>

 <object id=" ContactManager.views.contact.ListView"  type="ContactManager.views.contact.ListView" 
      extends=” Koossery.xxx.xxx.BaseView”>
    <property name="ViewName">
      <value>List your contacts</value>
    </property>
 </object>
</objects>


We create the ListView view; we inject the ViewName and the Session properties. Noticed that the spring-ContactManager_SESSIONS.xml is includedso that the Session objects can be retrieved from that file:
 import resource="spring-ContactManager_SESSIONS.xml"/> 
The last spring file is spring action file. This file contains xml declaration for creating controllers and the controller manager. Adds a XML file named spring-ContactManager_CONTROLLERS.xml in the spring folder. The listing 9 below shows the contains of the file

<?xml version="1.0" encoding="utf-8" ?>

<objects xmlns="http://www.springframework.net">

  <import resource="spring-ContactManager_VIEWS.xml"/>


  <!--Configuriing controllers-->
  <object id="ListController" type="ContactManager.controllers.contact.ListController">
    <property name="Session">
      <ref object="Session"/>
    </property>
  </object>
    
  <!--Manager-->
  <object id="ControllerManager" type="Koossery.MVCwin.ControllerManager.impl.ControllerManager, Koossery.MVCwin">
    <property name="DefaultController">
      <value>ListController</value>
    </property>

    <!--Controllers-->
    <property name="Controllers">
      <dictionary key-type="string" value-type="Koossery.MVCwin.Controller.itf.IController, Koossery.MVCwin">
        <entry key="ListController">
          <ref object="ListController"/>
        </entry>
      </dictionary>
    </property>

    <!--Views-->
    <property name="Views">
      <dictionary key-type="string" value-type="Koossery.MVCwin.Views.itf.IView, Koossery.MVCwin">
        <entry key="ListView">
          <ref object="ListView"/>
        </entry>
      </dictionary>
    </property>
  </object>
</objects>


The ListController is created at the section “Configuring Controllers”. The object Session is injected so that all view datas are accessible from any controller. The ControllerManager is created at the section “Manager”. The DefaultController property is injected. The DefaultController is executed when no controller is mentioned. The Controllers and Views dictionary are also injected with Controllers and Views.
Noticed that the sping view file is included. It implied that the spring session file is also included.

Last edited Jun 22, 2009 at 9:30 AM by koossery, version 2

Comments

No comments yet.