StructureMap: EqualToAppSetting with non string constructor argument

Considering

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

At

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

StructureMap then throws the following exception

No Default Instance defined for PluginFamily System.Decimal

Can EqualToAppSetting be used with non-string arguments?

+3
source share
1 answer

I do not think you can do this with the EqualToAppSetting method. Could you just reference System.Configuration and configure the application yourself? Like this...

      ForRequestedType<IBlah>()
        .TheDefault.Is.OfConcreteType<Blah>()
        .WithCtorArg("blah")
        .EqualTo(Convert.ToDecimal(ConfigurationManager.AppSettings["argument_app_setting_key"]));
+2
source

Source: https://habr.com/ru/post/1710553/


All Articles