This may be stupid question, but I am looking at Ninject sources and don't see NInject registering its own controller factory. I also don't see any IControllerFactory
class in Ninject.Web.Mvc
assembly. Am I missing something? How does Ninject create controller and inject parameters into constructor?
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- Entity Framework throws exception - Network Relate
- parameters in routing do not work MVC 3
- Slow loading first page - ASP.NET MVC
- Slow loading first page - ASP.NET MVC
相关文章
- “Dynamic operations can only be performed in homog
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
Since controllers are concrete types, Ninject will do self bind. Below is a snippet from
ninject.complex.com
If you do need to inject parameters into the constructor. You can create a class inherits from
INinjectModule
and do the binding there.DefaultControllerFactory
, the same as non-Ninject applications.DefaultControllerFactory
finds type for controller (TaskController
).DefaultControllerFactory
has internal class calledDefaultControllerActivator
.DefaultControllerActivator
has method calledCreate
, which returns controller instance.DefaultControllerFactory
asksDefaultControllerActivator
forTaskController
type instance.DefaultControllerActivator.Create
usesIDependencyResolver
. This is whereNinject
comes in. SinceNinject
implements its own resolver and sets it at the start of application, he gets request forTaskController
instance.Ninject
finds constructor for this type, injects parameters, returns controller instance.MVC3 now recommends the usage of the
IDependencyResolver
interface instead of the good oldIControllerFactory
when dealing with DI. You can look at more details of this interface here.This is the new Ninject class responsible for injecting the dependencies.