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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:21:45+00:00 2026-06-11T07:21:45+00:00

We use ninject in all our projects, and as you will know, sometimes it

  • 0

We use ninject in all our projects, and as you will know, sometimes it becomes hard to test if the kernel would be able to resolve every type at execution time, because sometimes control gets lost when the magnitude of bindings and autobindings (through ninject extensions) is high.

So, what I’m asking here is how can I know that my kernel, after loading all modules and bindings, will be able to resolve every type ? Do you do any kind of Unit Test? Or you just make acceptation tests of the application, at execution time? Any suggestion will be great 🙂

  • 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-11T07:21:46+00:00Added an answer on June 11, 2026 at 7:21 am

    Write an integration test that tests the container’s configuration by looping over all root types in the application and requesting them from the container/kernel. By requesting them from the container, you are sure that the container can build-up the complete object graph for you.

    A root type is a type that is requested directly from the container. Most types won’t be root types, but part of the object graph (since you should rarely call back into the container from within the application). When you test the creation of a root type, you will immediately test the creation of all dependencies of that root type, unless there are proxies, factories, or other mechanisms that might delay the construction process. Mechanisms that delay the construction process however, do point to other root objects. You should identify them and test their creation.

    Prevent yourself from having one enormous test with a call to the container for each root type. Instead, load (if possible) all root types using reflection and iterate over them. By using some sort of convention over configuration approach, you save yourself from having to 1. change the test for each new root type, and 2. prevent an incomplete test when you forgot to add a test for a new root type.

    Here is an example for ASP.NET MVC where your root types are controllers:

    [TestMethod]
    public void CompositionRoot_IntegrationTest()
    {
        // Arrange
        CompositionRoot.Bootstrap();
    
        var mvcAssembly = typeof(HomeController).Assembly;
    
        var controllerTypes =
            from type in mvcAssembly.GetExportedTypes()
            where typeof(IController).IsAssignableFrom(type)
            where !type.IsAbstract
            where !type.IsGenericTypeDefinition
            where type.Name.EndsWith("Controller")
            select type;
    
        // Act
        foreach (var controllerType in controllerTypes)
        {
            CompositionRoot.GetInstance(controllerType);
        }
    }
    

    UPDATE

    Sebastian Weber made an interesting comment to which I like to respond.

    What about delayed object creation using container backed (Func) or
    container generated factories (like Castle’s Typed Factory Facility)?
    You won’t catch them with that kind of test. That would give you a
    false feeling of security.

    My advice is about verifying all root types. Services that are created in a delayed fashion are in fact root types and they should therefore be tested explicitly. This does of course force you to monitor changes to your configuration closely, and add a test when you detect a new root type is added that can’t be tested using the convention-over-configuration tests that you already have in place. This isn’t bad, since nobody said that using DI and a DI container means that we may get careless all of a sudden. It takes discipline to create good software, whether you use DI or not.

    Of course this approach will get pretty inconvenient when you have many registrations that do delayed creation. In that case there is probably something wrong with the design of your application, since the use of delayed creation should be the exception, not the norm. Another thing that might get you in trouble is when your container allows you to resolve unregistered Func<T> registrations, by mapping them to a () => container.GetInstance<T>() delegate. This sounds nice, but this forces you to look beyond the container registration to go look for root types, and makes it much easier to miss one. Since usage of delayed creation should be the exception, you’re better off with explicit registration.

    Also note that even if you can’t test 100% of your configuration, this doesn’t mean that this makes testing the configuration is useless. We can’t automatically test 100% of our software and should take special care of that part of our software/configuration that can’t be tested automatically. You can for instance add untestable parts to a manual test script, and test them by hand. Of course, the more you have to test by hand, the more can (and will) go wrong, so you should try to maximize the testability of your configuration (as you should do with all of your software). You will of course get a false sense of security when you don’t know what your testing, but again, this holds for everything in our profession.

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

Sidebar

Related Questions

How to use this functionality in ninject 2.0? MyType obj = kernel.Get<MyType>(With.Parameters.ConstructorArgument(foo,bar)); The With
I would like to use Ninject in my WinForms application. I cannot figure out
I am learning Ninject as my first DI container, I guess all containers will
Can you use Ninject 2.0 with VS2010 RC1?
I am trying to properly use Ninject to inject log4net logging into my MVC3
I'm using Ninject 3.0.1.10 for dependency injection and want to use Ninject.Extensions.Logging 3.0.1.0 for
.. but not k.i.s.s.i.n.g I am trying to use NInject with NHibernate. Through NuGet
I want to use conditional binding in ninject, based on passed parameters. I have
I am learning to use dependency injection with ninject. Most of the properties and
I am attempting to use bbv.common.EventBroker with Ninject and am running into a few

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.