How does Ninject create controller in ASP.NET MVC?

后端 未结 3 1400
名媛妹妹
名媛妹妹 2021-01-02 04:05

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 IControllerFactor

3条回答
  •  北海茫月
    2021-01-02 05:02

    Since controllers are concrete types, Ninject will do self bind. Below is a snippet from ninject.complex.com

    Bear in mind that only concrete types can be self-bound; abstract types and interfaces won't work. Also, if you request an instance of a type that can be self-bound, and there are no bindings defined for the type, Ninject will automatically create an implicit self-binding. It's up to you whether you want to define your bindings explicitly, or let Ninject figure it out.

    If you do need to inject parameters into the constructor. You can create a class inherits from INinjectModule and do the binding there.

提交回复
热议问题