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

  • Home
  • SEARCH
  • 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 8681421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:30:22+00:00 2026-06-12T21:30:22+00:00

I am using the ninject mvc3 plugin with my web api application. I have

  • 0

I am using the ninject mvc3 plugin with my web api application. I have a binding that looks like:

kernel.Bind<IFoo>().To<Foo>().InSingletonScope();

It is my interpretation that the kernal will create exactly one instance of Foo and reuse it appropriately. By putting a breakpoint in Foo‘s constructor, I can clearly see that it is getting called once per request, and I cannot explain why.

My only guess is that somehow a new kernel is getting created per request, but that doesn’t appear to be the case, as the CreateKernel method which sets the global dependency resolver is only getting run once in the application lifetime.

I am using some code taken from this post to make ninject play nice with mvc 4. Because of framework changes, I had to make an additional wrapper that I assign to GlobalConfiguration.Configuration.DependencyResolver:

public class NinjectResolver : NinjectScope, IDependencyResolver
{
    private readonly IKernel _kernel;
    public NinjectResolver(IKernel kernel)
        : base(kernel)
    {
        _kernel = kernel;
    }
    public IDependencyScope BeginScope()
    {
        return new NinjectScope(_kernel.BeginBlock());
    }
}

What am I doing wrong?

  • 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-06-12T21:30:24+00:00Added an answer on June 12, 2026 at 9:30 pm

    I never could get it to work properly, and I am not sure why. My guess is it has something to do with MVC4 integration being a bit immature at the moment.

    As an alternative I am using:

    kernel.Bind<IFoo>().ToConstant(new Foo());

    This seems to work, but I am not too happy with it.

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

Sidebar

Related Questions

I have set up a NInject (using version 1.5) binding like this: Bind<ISessionFactory>().ToMethod<ISessionFactory>(ctx =>
I'm using Ninject.MVC3. private static void RegisterServices(IKernel kernel) { kernel.Bind<Repository>().To<Repository>(); } Registering them like
I have a MVC3 web application. I am using Ninject 2 for dependency injection
I have Ninject working nicely in an ASP.NET MVC3 web application. I'd like to
I am building a MVC3 app using Ninject framework. I have a service that
I've got a simple web application using ASP.NET MVC3 and Ninject.Web.MVC (the MVC3 version).
I have a MVC3 application that I would like to port to MVC4. I
I am currently creating an MVC3 application using Ninject. I have two controllers which
I'm starting a web application with MVC3 and Ninject. There is one dependency that
I'm creating an application that has a ASP.NET Web API interface using the Self

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.