Auto-wiring in StructureMap 2.5

While I was confused by other posts mentioning LookForRegistries() by scan assembly, Derik Whittaker’s post explained how to do auto-wire in SC2.5, that’s just what I want! But I couldn’t move this code into a Registry class. Meanwhile I saw Jeremy Miller kept saying:

Don’t ever make any calls to ObjectFactory within a Registry.

I’m not sure does this mean I am not supposed to do OBjectFactory.Configure() in my Registry. If no, how can I refactor this code?

        private static void SetupStructureMap()
                        // <a href="">Ingore config file</a>
                        x.UseDefaultStructureMapConfigFile = false


                        x.Scan(scanner =>


2 thoughts on “Auto-wiring in StructureMap 2.5

  1. Frank,

    I think what you have there is fine, you are not calling ObjectFactory from within the registry, you are dynamically creating the registry inside the initialize method. That is essentially what I am doing, except I have a seperate registry in each assembly and do this:

    ObjectFactory.Initialize(x =>
    x.AddRegistry(new InfrastructureRegistry());
    x.AddRegistry(new CoreRegistry());

  2. I’m actually thinking to adopt the idea of ‘having a separate registry in each assembly’ recently. So the hooking-up code in UI will be similar to the code I saw yesterday during the virtual conference:

    x.Scan(scanner =>

    I like this better because there is no string literal to describe the assembly name.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s