views:

9

answers:

1

OK, I'm stumped over a seemingly trivial piece of functionality.

How can I get StructureMap to initialize the properties on type instances retrieved from the container, using XML configuration (unfortunately I have to use XML)?

My current code is:

The type and interface:

public interface IMyType
{
  decimal MyProperty { get; set; }
}

public MyType : IMyType
{
  public decimal MyProperty {get; set; }
}

The container initialization and instance retrieval code:

ObjectFactory
  .Initialize(x => x.AddConfigurationFromXmlFile(@"StructureMap.config"));
IMyType instance = ObjectFactory.GetNamedInstance<IMyType>("Blah"); 
var myPropertyValue = instance.MyProperty; //expected 1, is actually 0

XML Configuration:

<?xml version="1.0" encoding="utf-8" ?>
<StructureMap MementoStyle="Attribute">  
  <AddInstance
    PluginType="MyNamespace.IMyType, MyAssemblyName"
    PluggedType="MyNamespace.MyType, MyAssemblyName"
    Key="Blah"
    Name="Blah
    MyProperty="1" />
</StructureMap>
A: 

This looks like a typing issue with StructureMap. Using an int, float or double works. Using a decimal does not.

Workaround is to use another floating point type such as float or double.

Ben Aston