More dribs and drabs of StructureMap 2.5 documentation. At the pace I’m on, I do believe that Duke Nukem Forever will be released tomorrow night. Knock on wood.
New to 2.5 is the ability to create an instance of the underlying Container class independent of the static ObjectFactory class (actually, you always could do this, but it’s much easier in 2.5). The IContainer interface has roughly the same methods as ObjectFactory (the only major difference is that ObjectFactory.GetNamedInstance<T>(name) is IContainer.GetInstance<T>(name) ) You can build a Container with a single Registry object:
Or more commonly, you can build the Container in a manner very similar to the ObjectFactory.Initialize() method. One of the constructors for Container takes in an Action<ConfigurationExpression> expression that can be used to configure the Container in one atomic action like this code below:
The ConfigurationExpression class is a Registry, so you can use all of the Registry DSL in the Lambda expression passed into the Container constructor. In addition to the Registry DSL, you also have these options:
These other options will allow you to add configuration from additional Registry classes, the StructureMap section in the App.config file, or other Xml files.
Lastly, you can create a Container directly with a no argument constructor, then use the Inject() methods or later use the Configure() method.