Where are people bootstrapping StructureMap?

8 views
Skip to first unread message

Brian Mavity

unread,
Jan 27, 2010, 9:04:37 AM1/27/10
to fubumv...@googlegroups.com
Hey everyone,

I think I'm missing something obvious here, so I figured it'd just save me time to ask here. Where exactly are people bootstrapping StructureMap in their FubuMVC apps? If I try to bootstrap before I create my custom FubuRegistry, all configuration gets reinitialized in the FubuStructureMapBootstrapper.

I saw in Joshua's post that he creates his own FubuStructureMapBootstrapper, but doesn't this defeat the purpose of having a default in the first place? I keep thinking that adding an AddRegistry<MyStructureMapRegistry>() method to the FubuStructureMapApplication would solve this problem.

What am I missing?

Rob G

unread,
Jan 27, 2010, 9:10:51 AM1/27/10
to fubumvc-devel
I'm having a similar beef with it at the moment trying to bootstrap the Spark stuff. I'm not sure I quite grok it yet... 

This is the last piece of the puzzle for me since I've got most Spark functionality working now including precompile and dynamic compilation methods, and I just need to figure out the proper bootstrapping mechanism and I can get some blog posts and examples out.

Let me know if you figure this one out....

--
You received this message because you are subscribed to the Google Groups "FubuMVC Development Group" group.
To post to this group, send email to fubumv...@googlegroups.com.
To unsubscribe from this group, send email to fubumvc-deve...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fubumvc-devel?hl=en.

Jeremy D. Miller

unread,
Jan 27, 2010, 9:18:25 AM1/27/10
to fubumv...@googlegroups.com
Guys,

The StructureMapBootstrapper is completely additive.  It doesn't wipe the Container.  You completely build up your container first, then pass it into StructureMapBootstrapper at the last minute to build out the Routes and add in more stuff to the Container.
 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: Rob G <robertg...@gmail.com>
To: fubumvc-devel <fubumv...@googlegroups.com>
Sent: Wed, January 27, 2010 8:10:51 AM
Subject: Re: [fubumvc] Where are people bootstrapping StructureMap?

Rob G

unread,
Jan 27, 2010, 9:25:30 AM1/27/10
to fubumvc-devel
Hmmm, that could be where I'm misunderstanding

What if we need some of the stuff (like RouteData) in order to complete the bootstrapping of our stuff? Am I going about it in reverse? I read your post about UrlResolution which pretty much deals with RunTime needs for Route Information, but at bootstrapping time, this info is a little hard to come by...

Am I missing something or is that intentional by design?

Thanks,
Rob

Brian Mavity

unread,
Jan 27, 2010, 9:26:25 AM1/27/10
to fubumv...@googlegroups.com
Jeremy,

I tried initializing the ObjectFactory before I returned my app specific FubuRegistry from the GetMyRegistry override. I dug into the Fubu code and saw this in FubuStructureMapBootstrapper:

private void BootstrapStructureMap(FubuRegistry fubuRegistry)
{
    UrlContext.Reset();

    ObjectFactory.Initialize(x => { });

    var fubuBootstrapper = new StructureMapBootstrapper(ObjectFactory.Container, fubuRegistry);

    fubuBootstrapper.Bootstrap(_routes);
}

Wouldn't that initialize overwrite any specific configuration done by me?

Jeremy D. Miller

unread,
Jan 27, 2010, 9:33:11 AM1/27/10
to fubumv...@googlegroups.com
Okay, nevermind.  Don't use that code except as an example.  UrlContext and the StructureMapBootstrapper are what's important.


From: Brian Mavity <bma...@gmail.com>
To: fubumv...@googlegroups.com
Sent: Wed, January 27, 2010 8:26:25 AM

Brian Mavity

unread,
Jan 27, 2010, 10:00:25 AM1/27/10
to fubumv...@googlegroups.com
That's too bad, I liked the idea that we could just inherit from an application class and get running. In the mean time, because I'm too lazy and it works, I changed the classes around a little so that I can initialize directly off of the StructureMapApplication. Looks like this:

MyApplication changes
public override void InitializeStructureMap(IInitializationExpression init)
{
    init.AddRegistry<CoreStructureMapRegistry>();

    init.AddRegistry<AutoMapperStructureMapRegistry>();
}

FubuSctructureMapApplication changes
public virtual void InitializeStructureMap(IInitializationExpression init)
{
    // no op
}

protected void Application_Start(object sender, EventArgs e)
{
    RouteCollection routeCollection = RouteTable.Routes;
    FubuStructureMapBootstrapper.Bootstrap(routeCollection, GetMyRegistry(), InitializeStructureMap);
}

FubuStructureMapBootstrapper changes
private void BootstrapStructureMap(FubuRegistry fubuRegistry, Action<IInitializationExpression> initialization)
{
    UrlContext.Reset();

    ObjectFactory.Initialize(initialization);

    var fubuBootstrapper = new StructureMapBootstrapper(ObjectFactory.Container, fubuRegistry);

    fubuBootstrapper.Bootstrap(_routes);
}

Josh Flanagan

unread,
Jan 27, 2010, 10:43:30 AM1/27/10
to fubumv...@googlegroups.com
As you've discovered, the classes in the "Bootstrap" namespace are
simplified for "just get me going" (the training wheels), and you will
quickly outgrow them. You can use the source of them as examples and
copy it into your own own bootstrapper once the need arises.

Chad Myers

unread,
Jan 27, 2010, 10:50:41 AM1/27/10
to fubumv...@googlegroups.com
Josh is right, but it does seem like it's 99% of what you need in this case, Brian.  I liked your proposed changes.


-Chad

Brian Mavity

unread,
Jan 27, 2010, 10:52:09 AM1/27/10
to fubumv...@googlegroups.com
Right now they aren't tested, but I can get some tests around the behavior and submit a pull request if you'd like.

Brian Mavity

unread,
Jan 27, 2010, 10:52:46 AM1/27/10
to fubumv...@googlegroups.com
Hah! I'm a little slow, never mind my last message. ;)
Reply all
Reply to author
Forward
0 new messages