Created
April 10, 2011 12:42
-
-
Save hyrmn/912309 to your computer and use it in GitHub Desktop.
How I did registration pre-turbine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Bootstrapper | |
{ | |
public static void Initialize() | |
{ | |
StructureMapConfigurator.ConfigureObjectFactory(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.