Created
March 31, 2014 17:25
-
-
Save hyrmn/9897427 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 StructuremapMvc | |
| { | |
| public static void Start() | |
| { | |
| var container = IoC.Initialize(); | |
| GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new StructureMapHttpControllerActivator(container)); | |
| } | |
| } |
This file contains hidden or 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 StructureMapHttpControllerActivator : IHttpControllerActivator | |
| { | |
| private readonly IContainer _container; | |
| public StructureMapHttpControllerActivator(IContainer container) | |
| { | |
| _container = container; | |
| } | |
| public IHttpController Create( | |
| HttpRequestMessage request, | |
| HttpControllerDescriptor controllerDescriptor, | |
| Type controllerType) | |
| { | |
| var nestedContainer = _container.GetNestedContainer(); | |
| nestedContainer.Inject(typeof(HttpRequestMessage), request); | |
| request.RegisterForDispose(nestedContainer); | |
| return (IHttpController)nestedContainer.GetInstance(controllerType); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment