Why won't Ninject resolve protected properties in a base class?

后端 未结 2 1451
南方客
南方客 2021-01-18 16:02

Simple question I guess, but I\'ve spent an hour trying to get a base class for my controllers to have a few services injected via property injection. The properties were s

2条回答
  •  不思量自难忘°
    2021-01-18 16:34

    You cannot inject into properties that do not have public setter. Both your Logger and Repository properties are protected so no way for Ninject to assign them a value. You will have to change their setter visibility if you want to achieve this. Or use constructor injection. While this would make perfect sense for the repository property which seems required it wouldn't make sense for the logger property. So I guess you will have to make it public.

提交回复
热议问题