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?

Mark Rogers
  • 96,497
  • 18
  • 85
  • 138

1 Answers1

5

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
  • 8,527
  • 2
  • 31
  • 40
  • Fair enough, I'm curious if you ever use conditional compiler directives in your structure map configuration code? Thx – Mark Rogers May 31 '10 at 22:48
  • 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 Jun 01 '10 at 01:07