views:

41

answers:

1

I have a bit of StructureMap config like so:

x.ForConcreteType<OrderProcessor>().Configure
    .Ctor<string>("param1").EqualToAppSetting("setting1")
    .Ctor<string>("param2").EqualToAppSetting("setting2")
    .Ctor<string>("param3").EqualToAppSetting("setting3");

This works, but it is a bit of a magic-string approach. If I add or remove a constructor parameter, or change its name, but forget to update the StructureMap config, I won't find out about it until runtime.

Is there an alternate syntax in StructureMap that is more strongly-typed? Is this even possible?

+1  A: 

My team moved away from injecting primitive arguments into constructor parameters mostly because of this issue. Instead, we create an object that has properties for all of the settings that need to be injected, and then do some tricks so that the object is automatically populated by the container from the config file.

You can read about it here:

http://www.lostechies.com/blogs/joshuaflanagan/archive/2009/07/12/how-we-handle-application-configuration.aspx

Joshua Flanagan