Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:23+00:00 2026-05-26T21:11:23+00:00

Simple question I guess, but I’ve spent an hour trying to get a base

  • 0

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 scoped protected at first, but the objects kept coming back null, once I changed the scope to public it worked. Is there anyway to have the properties be protected and get the IoC to 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 the boot-strapper in the 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>();
    } 

Thank you,
Stephen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:11:24+00:00Added an answer on May 26, 2026 at 9:11 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A fairly simple question for which I have a guess, but I can't find
I guess this is a quite simple (read: very simple) question, but I have
Probably a simple question but one that eludes me nonetheless. I have a class:
A little stuck here. I have a simple question I guess. Given the following
I have a simple question (i guess). I'm getting the name of the function
i have a (i guess) simple question. I am running Selenium test cases (HTML,
I guess it's a simple question, but how can I replace nil values in
This sounds like a relatively simple question, but I haven't been able to get
I guess my question is very simple, but I am new to php so
I guess my question is very simple, but anyway... I've created neural network using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.