Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created April 10, 2011 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrmn/912309 to your computer and use it in GitHub Desktop.
Save hyrmn/912309 to your computer and use it in GitHub Desktop.
How I did registration pre-turbine
public static class Bootstrapper
{
public static void Initialize()
{
StructureMapConfigurator.ConfigureObjectFactory();
}
}
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}
protected void Application_Start()
{
Bootstrapper.Initialize();
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
RegisterRoutes(RouteTable.Routes);
}
protected void Application_End()
{
}
}
public static void ConfigureObjectFactory()
{
ObjectFactory.Initialize(i =>
{
i.IgnoreStructureMapConfig = true;
i.For(typeof (IDataMapper<>)).Use(typeof (DataMapper<>));
i.AddRegistry(new NHibernateRegistry());
i.AddRegistry(new ServiceRegistry());
i.Scan(s =>
{
s.Assembly("KennelFinder");
s.WithDefaultConventions();
});
});
}
}
@hyrmn
Copy link
Author

hyrmn commented Apr 10, 2011

The app does some basic wiring on structuremap to configure it. It then sets the controller factory to a StructureMapControllerFactory that I had to write and provide (I believe NInject has a controller factory out of the box?)

It's all pretty straightforward and we're good to go. It doesn't easily encourage encapsulation of the various configuration tasks for an application though. And, one could argue that I've made it worse by attempting to break things out into their own static methods as the control flow isn't obvious (sorry about that!) but it is best practice from what I've learned/read/experienced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment