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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:37:20+00:00 2026-06-07T16:37:20+00:00

I am wiring up Ninject with MVC4 and have it working to the point

  • 0

I am wiring up Ninject with MVC4 and have it working to the point it’s trying to actually resolve dependencies. However, I am getting the following exception:

Method not found: ‘System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()’.

Anyone ran into this and have a work around?

  • 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-07T16:37:23+00:00Added an answer on June 7, 2026 at 4:37 pm

    GlobalConfiguration.Configuration.ServiceResolver was replaced with GlobalConfiguration.Configuration.DependencyResolver in the RC. So I guess the Ninject package you are using is simply not designed for the RC. It was one of the breaking changes.

    So here are the steps to make Ninject work with ASP.NET MVC 4 Web API RC:

    1. Create a new ASP.NET MVC 4 application using the Empty template
    2. Declare an interface:

      public interface IFoo
      {
          string GetBar();
      }
      
    3. Then an implementation:

      public class Foo : IFoo
      {
          public string GetBar()
          {
              return "the bar";
          }
      }
      
    4. Then add an API controller:

      public class ValuesController : ApiController
      {
          private readonly IFoo _foo;
          public ValuesController(IFoo foo)
          {
              _foo = foo;
          }
      
          public string Get()
          {
              return _foo.GetBar();
          }
      }
      
    5. Install the Ninject.Mvc3 NuGet package (Install-Package Ninject.Mvc3)

    6. Define a custom API dependency resolver as shown in this gist:

      public class NinjectDependencyScope : IDependencyScope
      {
          private IResolutionRoot resolver;
      
          internal NinjectDependencyScope(IResolutionRoot resolver)
          {
              Contract.Assert(resolver != null);
      
              this.resolver = resolver;
          }
      
          public void Dispose()
          {
              IDisposable disposable = resolver as IDisposable;
              if (disposable != null)
                  disposable.Dispose();
      
              resolver = null;
          }
      
          public object GetService(Type serviceType)
          {
              if (resolver == null)
                  throw new ObjectDisposedException("this", "This scope has already been disposed");
      
              return resolver.TryGet(serviceType);
          }
      
          public IEnumerable<object> GetServices(Type serviceType)
          {
              if (resolver == null)
                  throw new ObjectDisposedException("this", "This scope has already been disposed");
      
              return resolver.GetAll(serviceType);
          }
      }
      
      public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
      {
          private IKernel kernel;
      
          public NinjectDependencyResolver(IKernel kernel)
              : base(kernel)
          {
              this.kernel = kernel;
          }
      
          public IDependencyScope BeginScope()
          {
              return new NinjectDependencyScope(kernel.BeginBlock());
          }
      }
      
    7. In your ~/App_Start/NinjectWebCommon.cs/CreateKernel method that was created when you installed the NuGet add the following line after the RegisterServices(kernel); line:

      GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
      
    8. Configure your kernel:

      private static void RegisterServices(IKernel kernel)
      {
          kernel.Bind<IFoo>().To<Foo>();
      }        
      
    9. Hit F5 and navigate to /api/values

    10. You are presented with the bar.

    Obviously when the RC hits RTM I hope there will be a Ninject.Mvc4 NuGet that will shorten those 10 steps to maximum 5.

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

Sidebar

Related Questions

I'm wiring the following method to my document.ready function. However, the myAutoCompleteURL.aspx URL is
I have a problem with Ninject trying to resolve an interface type where the
With NInject (preferably 2.0), what options do we have wrt wiring up our object
I have a question about wiring web server controls. From many of the examples
We are wiring up our views and view models externally meaning we have the
I am working on an ASP.net Ajax custom control, I have tried to derive
I'm trying to create a new annotation with which I'll do some runtime wiring,
Loose coupling is wonderful of course, but I have often wondered what overhead wiring
I'm getting my hands on JSF 2.0 and have certain doubt about new annotation
I'm building an MVC4 app using EF5 and ninject. Something broke when I upgraded

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.