Why doesn't Ninject allow protected properties in the base class?

A simple question, I think, but I spent an hour trying to get a base class for my controllers in order to have several services introduced through property injection. At first, the properties were protected by the protection scope, but the objects returned zero as soon as I changed the scope to the publication. Is there a way to protect properties and make IoC work?

Here is my setup.

public class BaseController : Controller
{
    [Inject]
    protected LoggingInterface.ILogger<BaseController> Logger { set; get; }

    [Inject]
    protected IRepository Repository { set; get; }

    protected override void OnAuthorization(AuthorizationContext filterContext)
    {
        ....

        base.OnAuthorization(filterContext);
    }
}

and boot tape in NinjectMVC3 App_Start

    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind(typeof(LoggingInterface.ILogger<>)).To(typeof(Log4NetLogger<>));
        kernel.Bind<IRepository>().To<Repository>();
        kernel.Bind<IUserService>().To<UserService>();
    } 

Thanks Steven

+5
source share
2 answers

, . Logger Repository , Ninject . , . . , , logger. , .

+6

, InjectNonPublic NinjectSettings , , - ,

- , - - ( Injection : P)

+4

All Articles