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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:41:30+00:00 2026-05-31T13:41:30+00:00

I’ve started using Ninject in an ASP.NET MVC 3 project, using the standard boot

  • 0

I’ve started using Ninject in an ASP.NET MVC 3 project, using the standard boot strapper that comes with the nuget package, as below.

/// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
           // Documentation for setting up Ninject in ASP.NET MVC3 app: 
           // https://github.com/ninject/ninject.web.mvc/wiki/Setting-up-an-MVC3-application

           // Add bindings here. No modules required unless we need to add in further
           // separation of concerns.

           kernel.Bind<ISessionManager>().To<SessionManager>();
           kernel.Bind<ICookieManager>().To<CookieManager>();
           kernel.Bind<ILogManager>().To<LogManager>();
           kernel.Bind<IStringOutput>().To<StringOutput>();
    } 

Within my Domain Model layer, there is a class called CookieManager. Within my CookieManager class, I’m using a class called SecureObjectSerializer.

I want to use dependency injection so that the CookieManager is not tighly bound to the SecureObjectSerializer.

I don’t want the MVC project to have to know about the SecureObjectSerializer, setting up the bindings etc. That seems to be taking DI too far to me.

I do however, think that within the Domain Model layer, the CookieManager should have SecureObjectSerializer passed in in a DI manner.

My questions:

  1. To have the binding registered in the Domain Model layer, should I create a Ninject bootstrapper within the Domain Model layer? If so, how should I have this triggered. Would I supply a hook and call something like DomainModel.BindModelDependencies(kernel); in the MVC project.

  2. When it’s time to resolve a new instance of an object, what would this code look like? It’s kind of hidden when using the MVC bootstrapper?

  • 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-31T13:41:31+00:00Added an answer on May 31, 2026 at 1:41 pm

    You should put a NinjectModule inside of the domain assembly (not the web assembly) and you can tell ninject to scan your domain assembly and look for the module. module is just a class that inherits from NinjectModule base class and implements Load(). This way the web project only needs a reference to the domain project. the Scanning should look something like:

    either of these two: (actually there are a few more options but these are the main ones i use)

    var assemblysToScan = "Assembly.*";
    var assemblysToScan = new[] { "Assembly.Domain", "Assembly.Web" };
    

    and then just

    kernel.Scan(x =>
                    {
                        x.From(assemblysToScan)
                        x.AutoLoadModules();
                    });
    

    When you want to resolve an object, just put it as a ctor argument, and if ninject is managing you objects, it will inject the type (based on the bindings you have configured) automatically.

    EDIT:

    add references to ninjectcommonservicelocator (cant remember the exact name) & microsoft.practices.servicelocation

    in your bootstrapper add these:

    using Microsoft.Practices.ServiceLocation;
    using CommonServiceLocator.NinjectAdapter;
    
    var locator = new NinjectServiceLocator(kernel);
    ServiceLocator.SetLocatorProvider(() => locator);
    

    then in your class:

    using Microsoft.Practices.ServiceLocation;
    
    class CookieManager : ICookieManager
    {
      SecureObjectSerialiser secureObjectSerialiser;
    
      CookieManager()
      {
        this.secureObjectSerialiser = ServiceLocator.Current.GetInstance<SecureObjectSerialiser>();
      }
    }
    

    the reason for the microsoft.practices locator is your code should not know that ninject is working under the covers. instead, you use a generic servicelocator that can be reused if you change containers.

    personally i would avoid this and just inject everything. but if you cant, you cant.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.