views:

226

answers:

2

Is there a way to pass a type of a class as the value in Spring.NET?

My Dictionary looks like this:

private Dictionary<int, Type> ContentItemTypes { get; set; }

In code I would initialize as:

registry.addContentItemType(0, typeof(ContentItem));

How do you do this in Spring.NET. So far I have this:

<object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
  <property name="ContentItemTypes">
    <dictionary key-type="int" value-type="System.Type">
      <entry key="0">
        <value type="System.Type">Edu3.DomainModel.Framework.Model.ContentItem</value>
      </entry>
    </dictionary>
  </property>
</object>

Is this correct?

+1  A: 

maybe:

  <object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" value-ref="ContentItemType" ></entry>
      </dictionary>
    </property>
  </object>

  <object id="ContentItemType" type="System.Type, System" factory-method="GetType" singleton="false">
    <constructor-arg value="Edu3.DomainModel.Framework.Model.ContentItem" />
  </object>
Fabiano
+2  A: 

Or even shorter.

<object id="ContentItemTypeRegistry"
 type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
 factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" expression="T(Edu3.DomainModel.Framework.Model.ContentItem)" ></entry>
      </dictionary>
    </property>
  </object>
BennyM
Great, really need to check out those expressions. thx.
Lieven Cardoen