Loading modules in all assemblies in Ninject

后端 未结 4 1190
遥遥无期
遥遥无期 2021-01-31 06:12

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

4条回答
  •  萌比男神i
    2021-01-31 06:46

    You can use reflection to find and instantiate the Ninject modules:

    BuildManager.GetReferencedAssemblies()
        .Cast()
        .SelectMany(a => a.DefinedTypes)
        .Where(t => typeof(INinjectModule).IsAssignableFrom(t))
        .Select(t => (INinjectModule)Activator.CreateInstance(t))
    

提交回复
热议问题