The StructureMap.Config File

More docs.  I’m working on it.

 

In the beginning, StructureMap configuration began and ended with a single file named "StructureMap.config" in the application base folder that contained StructureMap Xml configuration (in short, wherever your App.config file would go).  Today, the default behavior is that StructureMap will automatically read in configuration data from the StructureMap.config if it is found when either ObjectFactory.Initialize() is called, or the first time that a service is requested from ObjectFactory.  You can technically use only the StructureMap.config file and completely forgo the the usage of any programmatic bootstrapping.

You can override the default behavior for the StructureMap.config file.  If you want to make the StructureMap.config file mandatory, you can do this:

            ObjectFactory.Initialize(x =>

            {

                // We put the properties for an NHibernate ISession

                // in the StructureMap.config file, so this file

                // must be there for our application to

                // function correctly

                x.UseDefaultStructureMapConfigFile = true;

            });

At other times you might want to force ObjectFactory to ignore the StructureMap.config file even if it does exist.

            ObjectFactory.Initialize(x =>

            {

                x.IgnoreStructureMapConfig = true;

            });

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.