Created
June 8, 2016 13:13
-
-
Save Kashkovsky/1d05bdadd10017c28e263c937f0f50b6 to your computer and use it in GitHub Desktop.
Ninject Controller Factory
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
using Ninject; | |
using System; | |
using System.Web.Mvc; | |
namespace Factories | |
{ | |
public class NinjectControllerFactory : DefaultControllerFactory | |
{ | |
public IKernel Kernel { get; private set; } | |
public NinjectControllerFactory(IKernel kernel) | |
{ | |
this.Kernel = kernel; | |
} | |
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) | |
{ | |
IController controller = null; | |
if (controllerType != null) | |
controller = (IController)Kernel.Get(controllerType); | |
return controller; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment