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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:50:42+00:00 2026-05-31T06:50:42+00:00

Inheriting from MVC Controller Class public class BaseController : Controller { private ITenantRepository _repository;

  • 0

Inheriting from MVC Controller Class

public class BaseController  : Controller
{

    private ITenantRepository _repository;
    [Inject]
    public BaseController(ITenantRepository repository)
    {
        _repository = repository;
    }
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        base.Initialize(requestContext);
    }
}

can’t build

BaseController’ does not contain a constructor that takes 0 arguments

clearly I am missing something obvious.

  • 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-31T06:50:43+00:00Added an answer on May 31, 2026 at 6:50 am

    In your child controllers make sure that you have defined a constructor with the same parameters as your base class:

    public class FooController: BaseController
    {
        public FooController(ITenantRepository repository): base(repository)
        {
        }
    
        ...
    }
    

    You need to do this because in the base class you have removed the parameterless constructor and replaced it with a custom one. So derived classes must also be removed from their parameterless constructor.

    Also note that the normal way of using Ninject with ASP.NET MVC is to set it up as the DependencyResolver at the top level of your app. The controllers should not use any container-specific attributes such as the [Inject] attribute you used as these tie your code to the dependency injection container you are using.

    Note as well that in addition to being bad practice from the preceding perspective, the [Inject] attribute on the constructor in your code has no material effect:

    • Nothing is going to step in and say ‘Look, it’s got an attribute, we better provide its dependencies’
    • If you do have Ninject configured as the DependencyResolver, it won’t need the attribute as there’s no ambiguity whatsoever as to what’s needed to construct the controller
      • there’s no default constructor
      • there’s no competing constructor
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class inheriting from QGraphicsLineItem and as soon as I override the
I have a simple class inheriting from WebControl as follow: public class Instrument :
Say I am inheriting from a class with several overloaded constructors. By any chance
I wish to declare a new dojo class inheriting from an existing dojo class,
Is the route table available from the filters? I'm inheriting from the AuthorizeAtrribute class.
Why I have problem creating a class inheriting from str (or also from int)
I have a class inheriting from UserControl, with a custom DependencyProperty. I put a
I have a MVC class where i am inheriting INotifyPropertyChanged I have a clock
I have a class that's currently inheriting from Dictionary and then adds a few
When inheriting from a class, you know the requirements and restrictions imposed on you

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.