Question

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 ?

Was it helpful?

Solution

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"]));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top