views:

40

answers:

1

I know that in StructureMap I can read from my *.config files (or files referenced by them), when I want to pass specific arguments to an object's constructor.

ForRequestedType<IConfiguration>()
                .TheDefault.Is.OfConcreteType<SqlServerConfiguration>()
                .WithCtorArg("db_server_address")
                .EqualToAppSetting("data.db_server_address")

But what I would like to do is read from one config setting in debug mode and another in release mode.

Sure I could surround the .EqualToAppSetting("data.db_server_address"), with #if DEBUG, but for some reason those statements make me cringe a little when I put them in. I'd like to know if there was some way to do this with the StructureMap library itself.

So can I feed my objects different settings based on whether the project is built in debug or release mode?

+2  A: 

StructureMap has no built-in detection of "debug" or "release" mode.

However, when you programmatically configure StructureMap via its DSL (in a Registry, or a call to Initialize() or Configure() on the container), you are using the C# language. You can do anything that C# allows. So your question becomes "is there a way in c# to conditionally run some code differently in debug mode", to which the most obvious answer will likely be the conditional compilation directives that make you feel bad.

Joshua Flanagan
Fair enough, I'm curious if you ever use conditional compiler directives in your structure map configuration code? Thx
Mark Rogers
No, I would prefer to use a more externally visible setting to switch configurations. Either read the compilation "debug" setting in web.config (it is exposed by some property), or an appSetting. That way I can easily switch it on or off, regardless of how the code was compiled.
Joshua Flanagan
Cool, thanks for the info!
Mark Rogers