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 7434679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:56:00+00:00 2026-05-29T09:56:00+00:00

Scenario: An MVC3 app that uses constructor injection to provide services for a given

  • 0

Scenario:

An MVC3 app that uses constructor injection to provide services for a given controller:

public class HomeController : BaseController
{
    private readonly IArticleService _articleService;

    public HomeController(IArticleService articleService)
    {
        _articleService = articleService;
    }

    public ActionResult Index()
    {
        // do stuff with services
        return View()
    }
}

Intention:

I have a UserService that fetches user principal data from Active Directory that I want usable from all my Controllers, from the base controller.

I have tried to inject this service into my BaseController like this:

public class BaseController : Controller
{
    private readonly IUserService _userService;

    public BaseController(IUserService userService)
    {
        _userService = userService;
    }
}

All by itself it looks fine, but now the constructor in my HomeController is off, as it needs a : base() initializer. The trouble is, the base initializer is not parameterless due the UserService injection.

public HomeController(IArticleService articleService) : base(IUserService userService)

The code above results in syntax errors.

Question(s):

How do I properly inject a service into my BaseController and initialize it from the child Controller classes (ex. HomeController)?

  • 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-29T09:56:01+00:00Added an answer on May 29, 2026 at 9:56 am

    The user service interface must be included in the child controllers’ constructor arguments in addition to the base initializer arguments. Like this:

    public class HomeController : BaseController
    {
        private readonly IArticleService _articleService;
    
        public HomeController(IArticleService articleService, IUserService userService) : base(userService)
        {
            _articleService = articleService;
        }
    
        public ActionResult Index()
        {
            // do stuff with services
            return View()
        }
    }
    

    Note: in order to do anything with the base controller’s UserService from the inherited controllers, change the access modified from private to protected.

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

Sidebar

Related Questions

Scenario: An event is raised in class A that needs to be handled by
ASP.NET MVC3 newb here. I am working on a MVC3 intranet application that uses
I have an ASP.NET MVC3 app that features a form with a nested-table input
Scenario: Assume I want to define my own class. public class Person { }
Folks, I have an MVC3 data entry form scenario that involves asking the user
The tutorial application, MusicStore -MVC3 (92 PageNo) , created a POCO class like: public
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario is that we send out thousands of emails through SMTP server. Content is
I am trying to implement a scenario of cascading dropdown with MVC3 & Knockout
Scenario: Most smartphones have a high resolution camera that generates photos that may range

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.