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 -----]