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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:38:15+00:00 2026-05-26T09:38:15+00:00

I have couple of class libraries in my project and all are using Ninject

  • 0

I have couple of class libraries in my project and all are using Ninject IoC container. I wanted to load all the modules in a StandardKernel at one go wherever an INinjectModule is found. So I used:

var kernel = new StandardKernel();
kernel.Load(AppDomain.CurrentDomain.GetAssemblies())

But this doesn’t work for some reason. Can anyone help?

  • 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-26T09:38:15+00:00Added an answer on May 26, 2026 at 9:38 am

    Well, this often happens when bindings are declared but other modules are loaded where that module tries to resolve a binding which has not loaded yet. This happens because List<INinjectModule> may not in the right order.

    If you think this is the case. Follow this resolution.

    The idea is we will have a bootstapper for each assembly, where the bootstrapper will be responsible to load the modules in its logical order.

    Let us consider an interface for bootstrapper (this we will use to find the bootstrapper in an assembly)

    public interface INinjectModuleBootstrapper
    {
        IList<INinjectModule> GetModules();
    }
    

    Now consider for your DataAccess assembly, implement the INinjectModuleBootstrapper:

    public class DataAccessBootstrapper : INinjectModuleBootstrapper
    {
        public IList<INinjectModule> GetModules()
        {
            //this is where you will be considering priority of your modules.
            return new List<INinjectModule>()
                       {
                           new DataObjectModule(),
                           new RepositoryModule(),
                           new DbConnectionModule()
                       };
            //RepositoryModule cannot be loaded until DataObjectModule is loaded
            //as it is depended on DataObjectModule and DbConnectionModule has
            //dependency on RepositoryModule
        }
    }
    

    This is how you defne the Bootstrapper for all your assembly. Now, from your program startup, we need the StandardKernel where all the modules are loaded. We will write something like this:

    var assemblies = AppDomain.CurrentDomain.GetAssemblies();
    return BootstrapHelper.LoadNinjectKernel(assemblies);
    

    And our BootstrapperHelper class is:

    public static class BootstrapHelper
    {
        public static StandardKernel LoadNinjectKernel(IEnumerable<Assembly> assemblies)
        {
            var standardKernel = new StandardKernel();
            foreach (var assembly in assemblies)
            {
                assembly
                    .GetTypes()
                    .Where(t =>
                           t.GetInterfaces()
                               .Any(i =>
                                    i.Name == typeof(INinjectModuleBootstrapper).Name))
                    .ToList()
                    .ForEach(t =>
                                 {
                                     var ninjectModuleBootstrapper =
                                         (INinjectModuleBootstrapper)Activator.CreateInstance(t);
    
                                     standardKernel.Load(ninjectModuleBootstrapper.GetModules());
                                 });
            }
            return standardKernel;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only one class with many instances. Every instance is observer of couple
I have couple of input fields with the class link. All of them should
I have a couple questions. Are all functions inside of a class member functions?
We have a couple of utility functions declared on class level in jsp. Using
I have a couple of Divs which I style using a class and an
I have one base class BASE and couple inherited class BASE_1, BASE_2,, BASE_3. I
I have a couple of classes, all derived from the same base type. class
I have a couple of functions inside a class that essentially do the same
Say I have a couple of basic objects like so: [Serializable] public class Base
I have a couple of ListPreferences that my PreferenceActivity displays. From the class that

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.