Disable implicit binding/injection of non explicitly bound classes in Ninject 2+

后端 未结 2 2081
旧时难觅i
旧时难觅i 2021-02-09 02:44

If you request an unbound object from NInject, then the default behaviour is (if a suitable constructor is available) appears to be to create an instance of the appropriate obje

2条回答
  •  不思量自难忘°
    2021-02-09 02:50

    The following is a better, more direct way of removing the SelfBindingResolver, without assuming that the DefaultValueBindingResolver is the only other IMissingBindingResolver component:

    kernel.Components.Remove();
    

    It's possible the Remove() method was only added in a recent version of Ninject, but this works for me using Ninject 3.2.2.0.

提交回复
热议问题