Using property injection instead of constructor injection

后端 未结 5 1043
时光取名叫无心
时光取名叫无心 2021-01-04 09:47

Long story short, I\'m trying to use ELMAH with MVC 2 and Ninject, and I need to use parameterless constructors. I created an initial post about it here: Using a parameterle

5条回答
  •  無奈伤痛
    2021-01-04 09:58

    There could be 2 reasons for object reference not set exception.

    1) Ninject does not know how to Bind IDepartmentsRepository to a concrete implementation of DepartmentsRepository ( I doubt that is the case though )

    2) If you are trying to access DepartmentsRepository property in your controller's constructor, it will throw the exception (since Ninject is only able to inject Property Dependencies after the object is constructed).

    Hope that helps.

提交回复
热议问题