This project is read-only.

StructureMap Extension

The StructureMap extension will help you intialize your StructureMap container by scanning for classes that implement StructureMapRegistration and executing it's register method.


You can install the StructureMap extension via nuget over here.

Creating Registrations

To initialize your container you must declare classes that implements IStructureMapRegistration and implement the Register method. For example:
    public class RegisterMyTypes: IStructureMapRegistration
        public void Register(IContainer container)
            container.Configure(c => c.For<IMyType>().Use<MyType>());

Native Registrations (new in

Bootstrapper now supports the use of native registrations. Native registrations can be used by themselves or in conjunction with Bootstrapper generic and specific registration. For StructureMap, just declare a class that inherits from StructureMap.Configuration.DSL.Registry and Bootstrapper will use it to initialize the container.
    public class TestStructureMapRegistry: Registry
        public TestStructureMapRegistry()

Using the extension

To use the extension simply write this code:


You can use the AutoRegistration option to indicate that you want to automatically register al types that implement an interface of the same name. For example, if you have an interface called IMyType and a type called MyType that implements IMyType then the Autoregistration option will Bind IMyType to MyType. To use the AutoRegistration option simply write this code:

Accessing the initialized Container

After Bootstrapper has been invoked and the container has been initialized it can be accessed with the Container property of Boostrapper. For example:
   var container = (IContainer)Bootstrapper.Container;

Using An Existing Container (new in

You can tell Bootstrapper to use an existing container instead of creating a new one like this:

ObjectFactory (new in

You can tell Bootstrapper to initialize the ObjectFactory container instead of creating a new one like this:

Generic Registration

You can use Generic Registration with the Ninject extension. For details go to the Generic Registration page.

Last edited Apr 11, 2013 at 4:36 AM by luisbocaletti, version 14


No comments yet.