Skip to content

Instantly share code, notes, and snippets.

@EfrainReyes
Created November 28, 2014 03:20
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 EfrainReyes/ccb0ee9de017330608bb to your computer and use it in GitHub Desktop.
Save EfrainReyes/ccb0ee9de017330608bb to your computer and use it in GitHub Desktop.
With this StructureMap Registry you can inject static and global objects like HttpContext and Session into your MVC controllers and any other helper classes you may have. Taken from Matt Honeycutt's pluralsight course on Building your own Application Framework
public class MvcRegistry : Registry
{
public MvcRegistry() {
For<BundleCollection>().Use(BundleTable.Bundles);
For<RouteCollection>().Use(RouteTable.Routes);
For<IIdentity>().Use(() => HttpContext.Current.User.Identity);
For<HttpSessionStateBase>()
.Use(() => new HttpSessionStateWrapper(HttpContext.Current.Session));
For<HttpContextBase>()
.Use(() => new HttpContextWrapper(HttpContext.Current));
For<HttpServerUtilityBase>()
.Use(() => new HttpServerUtilityWrapper(HttpContext.Current.Server));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment