Created
November 28, 2014 03:20
-
-
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
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 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