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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:48:46+00:00 2026-05-29T19:48:46+00:00

I am learning ASP.NE4 MVC3. I have created a NinjectDependencyResolver class, but I want

  • 0

I am learning ASP.NE4 MVC3. I have created a NinjectDependencyResolver class, but I want to know how I would go about implementing the ServiceLocator class. Currently I get this error “The type SportsStore.WebUI.Infrastructure.NinjectDependencyResolver does not appear to implement Microsoft.Practices.ServiceLocation.IServiceLocator.
Parameter name: commonServiceLocator”.

Global.asax
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            RegisterDependencyResolver();

            //ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
        }

        private void RegisterDependencyResolver()
        {
            var kernel = new StandardKernel();

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

        }

        NinjectDepencyResolver cs
            public class NinjectDependencyResolver 
    {
        private readonly IKernel _kernel;

        public NinjectDependencyResolver(IKernel kernel)
        {
            _kernel = kernel;
        }

        public object GetService(Type serviceType)
        {
            return _kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            try
            {
                return _kernel.GetAll(serviceType);
            }
            catch (Exception)
            {
                return new List<object>();
            }
        }
  • 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-29T19:48:49+00:00Added an answer on May 29, 2026 at 7:48 pm

    I would not do it like that. For one thing, Mark Seemann’s book “Dependency Injection in .NET” clearly shows that Service Locator is actually an anti-pattern.

    At any rate try not to bloat your global.asax file

    If you instead used Nuget and got the latest version of NinjectMVC3 , you should end up with a clean Application_Start method

       protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
    
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    

    However, if you want to you can add in this line into the end of that method as I believe this is what Adam and Steve do in the Sportstore application in the Apress MVC3 book.

    ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
    

    Since that book was released, Ninject released newer versions that make it much easier, in fact I would guarantee that the Apress MVC4 book that ends up coming out will show the simpler way. The simple way is use nuget and get NinjectMVC3 , then it will have an App_Start folder which will run the files in them at start of the application.

    Here is an example of it with some bindings

     using Products.Data.Abstract;
     using Products.Data.Concrete;
     using Products.Data.Infrastructure;
    
     [assembly:  WebActivator.PreApplicationStartMethod(typeof(ProductsWeb.App_Start.NinjectMVC3), "Start")]
     [assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(ProductsWeb.App_Start.NinjectMVC3), "Stop")]
    
     namespace ProductsWeb.App_Start
     {
      using System.Reflection;
      using Microsoft.Web.Infrastructure.DynamicModuleHelper;
      using Ninject;
      using Ninject.Web.Mvc;
    
    public static class NinjectMVC3 
    {
        private static readonly Bootstrapper bootstrapper = new Bootstrapper();
    
        /// <summary>
        /// Starts the application
        /// </summary>
        public static void Start() 
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
            DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
            bootstrapper.Initialize(CreateKernel);
        }
    
        /// <summary>
        /// Stops the application.
        /// </summary>
        public static void Stop()
        {
            bootstrapper.ShutDown();
        }
    
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            RegisterServices(kernel);
            return kernel;
        }
    
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
    
            kernel.Bind<IProductsRepository>().To<FakeProductsRepository>();
            kernel.Bind<MovieRepository>().To<MovieRepository>();
    
        }        
    }
    

    }

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

Sidebar

Related Questions

I am learning ASP.NET and would like to know what are the must have
I'm learning ASP.NET MVC3 and doing an application with CMS capabilities - but have
I am learning ASP.Net. I have a dynamically created ImageButton that I would like
I have been learning ASP.NET MVC for a few months. I have learned about
I am learning ASP MVC and I have problem. I have class Company with
I'm learning asp.net. I have question about example buttons I can use two types
I am learning ASP.NET MVC now a days and I have found that most
I have been learning ASP.NET by experimenting, watching videos on ASP.NET, and reading forums.
I am learning asp.net but I'm finding some problems. My doubt is how to
I am learning ASP.NET and I have a master-detail scenario using two GridViews in

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.