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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:54:06+00:00 2026-05-23T01:54:06+00:00

I have a feeling this should be a common requirement, but I can’t work

  • 0

I have a feeling this should be a common requirement, but I can’t work the proper way of doing it. I currently have a standard MVC3 site which is using Ninject to inject service classes (in singleton scope) from Project A into the constructor of the controllers – this is all working fine.

I have another class library – Project B – which requires classes from Project A. What I am wanting to do is inject the same singleton instance I use between in my MVC project within the Project B classes. Is this possible?

Currently in the global.asax, I have this for setting up the bindings.

private void SetupDependencyInjection()
        {
            // Create Ninject DI kernel
            IKernel kernel = new StandardKernel();

            kernel.Bind<IRepositoryA>().As<RepositoryA>().InSingletonScope();
            // A load more binding go here...

            // Tell ASP.NET MVC 3 to use our Ninject DI Container
            DependencyResolver.SetResolver(new NinjectResolver(kernel));
        }

Within my controller, I have something like

public ExampleController(IRepositoryA iRepositoryA, more params....)
        {
            this.iRepositoryA= iRepositoryA;
            var ProjectB.Class1 = new ProjectB.Class1(this.iRepositoryA);
            // more setup of params here....
        }

I have two classes in ProjectB which look like this

public class Class1
{
 public Class1(IRepositoryA iRepositoryA, more params...)
 {
  var class2 = new Class2(iRepositoryA, more params...);
 }
}

public class Class2
{
  public Class2(IRepositoryA iRepositoryA, more params...)
  {
   // Something goes here....
  }
}

What I am looking to do is instantiate a new instance of ProjectB.Class1 without having to pass iClass (plus potentially a load more) as a parameter. I believe I can expose IKernel from the global asax and then do something like iKernel.Get(). Is this the best way of doing this? The other problem I see is that the parameters injected into the controller may go down 3 or more levels, e.g. like example above, but contining further that just to Class2. Is it best in this instance to just keep passing the parameters down the chain?

  • 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-23T01:54:07+00:00Added an answer on May 23, 2026 at 1:54 am

    You controller needs a Class1 instance, not an IRepositoryA, so the solution is to require a Class1 instance in your controller’s constructor:

    public ExampleController(Class1 class1) {
        this.class1 = class1;
    }
    
    // Let Ninject provide these dependencies!
    public Class1(IRepositoryA repositoryA, Dependency2 dependency2) {
        this.repositoyA = classB;
        this.dependency2 = dependency2;
    }
    

    (And see Dependency Injection Myth: Reference Passing)

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

Sidebar

Related Questions

I have a feeling this is a repost but I can't seem to find
I have a feeling that I already know the answer to this one, but
I have a feeling that there must be client-server synchronization patterns out there. But
Ok I have a question and it is probably very easy but I can
OK i have seen other posts about this but none really specifically answer my
I have the feeling that is easy to find samples, tutorials and simple examples
I have the feeling that Flash -based ( or Silverlight -based) websites are generally
I curious to how different people solve integration of systems. I have a feeling
I'm the leader of a small web development team, and I have a feeling
I often work with text files which have a variable amount of whitespaces as

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.