Created
July 13, 2014 21:08
-
-
Save StacyGay/017173056e3a841c4914 to your computer and use it in GitHub Desktop.
ControllerFactory example
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 ControllerFactory : DefaultControllerFactory | |
{ | |
private readonly IUnityContainer _container; | |
private readonly SessionContainerManager _containerManager; | |
public ControllerFactory(IUnityContainer container, SessionContainerManager containerManager) | |
{ | |
_containerManager = containerManager; | |
_container = container; | |
} | |
protected IUnityContainer GetChildContainer(RequestContext requestContext) | |
{ | |
return _containerManager.GetContainer(); | |
} | |
public override IController CreateController(RequestContext requestContext, string controllerName) | |
{ | |
var controllerType = GetControllerType(requestContext, controllerName); | |
var container = GetChildContainer(requestContext); | |
return container.Resolve(controllerType) as IController; | |
} | |
public override void ReleaseController(IController controller) | |
{ | |
_container.Teardown(controller); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment