Since controllers are created using spring.net we can inject the concrete service implementation by configuration. Right click on the config\spring folder and add an XML file. Name the file spring-ContactManager_MODEL.xml. The xml file contains spring declaration for the creation of the concrete model. The xml file should look like the following:

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

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

  <object id="ContactManagerLocal" type="ContactManager.model.ContactManagerLocal, ContactManager"/>
    
</objects>


Once the file is saved, we need to edit the spring controller file in order to inject the concrete implementation using the constructor way. Edit the spring controller file, add the following import

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

Modify the 2 controllers declaration to take advantage of the dependency injection framework as shown below:

<!--Configuriing controllers-->
  <object id="ListController" type="ContactManager.controllers.contact.ListController">
    <!--Injecting the concrete implementation-->
    <constructor-arg index="0">
      <ref object="ContactManagerLocal" />
    </constructor-arg>
    <property name="Session">
      <ref object="Session"/>
    </property>
  </object>
  <object id="SaveController" type="ContactManager.controllers.contact.SaveController">
    <!--Injecting the concrete implementation-->
    <constructor-arg index="0">
      <ref object="ContactManagerLocal" />
    </constructor-arg>
    <property name="Session">
      <ref object="Session"/>
    </property>
  </object>

Last edited Jun 23, 2009 at 12:16 AM by koossery, version 1

Comments

No comments yet.