Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Using your app.config (web.config) to store your StructureMap settings

With the most recent drop of StrcutreMap (2.4.9 -- aka 2.5) you now have the ability to put your wiring information inside the app.config file.  Prior to this you needed to either use the StructureMap.config file or wire your dependencies up in code. So today I thought I would simply review how to use this new feature and show how simple and easy it is.

***** Disclaimer *****
Yes, I know that some people think that using attributes for IoC wiring is evil, but I like it.  Also, because most of the stuff I work on is 'API' like, I tend to not have a single entry point so using the config files is the path with the least amount of friction.
***** End Disclaimer *****

If you have ever used the StructureMap.config file you know that a sample layout would look something like this:

<StructureMap>
<Assembly Name="Assembly_NAME_HERE" />
</StructureMap>

Well, the good news is that adding your config to an app.config (or web.config) is almost 100% the same.  Below you will find a simple app.config that has my StructureMap information inside it

<configuration>
<configSections>
<section name="StructureMap" type="StructureMap.Configuration.StructureMapConfigurationSection, StructureMap"/>
</configSections>
<StructureMap>
<Assembly Name="Assembly_NAME_HERE" />
<Assembly Name="Assembly_NAME_HERE" />
</StructureMap>

</configuration>

Just so you know, in order to use the app.config as your source, you do need to add on line of code to your application.

StructureMapConfiguration.PullConfigurationFromAppConfig = true;

So there you go, moving from the StructureMap.config to an app.config is easy and should be fairly painless.

Hope this helps.

Till next time,

[----- Remember to check out DimeCasts.Net -----]


Posted 07-24-2008 11:51 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Chrissie1 wrote re: Using your app.config (web.config) to store your StructureMap settings
on 07-24-2008 2:56 PM

I like the attributes very much. So keep using them. Allthough I like that new feature where it wires up the interface and implementation automagically when interface and class have the same name (apart from th I). But that is my lazy side ;-).

Brian Johnston wrote re: Using your app.config (web.config) to store your StructureMap settings
on 07-24-2008 8:24 PM

I was curious if you think you could do a 'hello world' on structure maps sometime...I keep reading about it on here and the site for it just gets you straight down in the weeds...I have one of those personalities of 'show me a simple demo' and from that simple demo I can determine whether it's a good fit for our team or not, versus doing 'real' research (pathetic I know).  I live for 'hello words' - it's how I decided I wanted to learn .NET instead of Java...the hello world made more sense.

You seem to enjoy them so I figured I'd ask - I'm sure I'm not the only one with a passing curiosity that isn't strong enough to go digging through the weeds to find out more...or if you have 'hello world' links you could pass along?  I mean conceptually - yeah, no biggie, potentially very help framework - but I want to see a simple walk-through of getting something going from scratch to sell me.

Joshua Flanagan wrote re: Using your app.config (web.config) to store your StructureMap settings
on 07-25-2008 10:18 AM

Brian - hope this helps:

flimflan.com/.../HelloStructureMap.aspx

Chad Myers' Blog wrote StructureMap: Interlude
on 07-26-2008 1:54 PM

I&#39;m trying to wrap up the &quot;StructureMap: Advanced Scenarios Usage&quot; post. In the meantime

Dale Smith wrote re: Using your app.config (web.config) to store your StructureMap settings
on 08-17-2008 3:52 PM

@Brian - I swiped some of Joshua's code and cobbled together a sample app using StructureMap 2.0 instead of the 2.4.9 preview version.  Here it is:

creedcultcode.blogspot.com/.../boba-fett-greedo-and-structuremap.html

Isolated Unit Testing using Rhino Mocks and StructureMap at Inveigled By Design wrote Isolated Unit Testing using Rhino Mocks and StructureMap at Inveigled By Design
on 01-31-2009 7:53 PM

Pingback from  Isolated Unit Testing using Rhino Mocks and StructureMap at Inveigled By Design

Joshua Flanagan wrote Hello StructureMap
on 05-11-2010 7:54 AM

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)