StructureMap : EqualToAppSetting with non string constructor argument

Go To StackoverFlow.com

3

Given

public class Blah : IBlah 
{
    public Blah(decimal argument)
    {
    }
}

When

ForRequestedType<IBlah>()
    .TheDefault.Is.OfConcreteType<Blah>()
    .WithCtorArg("argument")
    .EqualToAppSetting("argument_app_setting_key")

Then StructureMap throws the following exception

No Default Instance defined for PluginFamily System.Decimal

Is there any way to use the EqualToAppSetting with non-string arguments ?

2009-06-16 09:14
by NoName


2

I don't think you can do this with the EqualToAppSetting method. Could you not just reference System.Configuration and cast the app setting yourself? Like this...

      ForRequestedType<IBlah>()
        .TheDefault.Is.OfConcreteType<Blah>()
        .WithCtorArg("blah")
        .EqualTo(Convert.ToDecimal(ConfigurationManager.AppSettings["argument_app_setting_key"]));
2009-06-17 17:20
by JamieGaines
Ads