简体   繁体   中英

Ninject multiple assemblies in windows service

I want to use ninject modules to bind my interfaces. I also want to be able to access the kernel and use the [Inject] attribute in any code of my assemblies. How do I do this? I have tried having a dependency resolver which contains all the modules. Is it better to have one kernel per assembly ?

You can and most likely should use only one kernel. The modules of the assemblies should be 'public'. Your application needs to reference these assemblies and load the modules, like

using(var kernel = new StandardKernel()) {
    kernel.Load<SomeModule>;
    kernel.Load<SomeOtherAssembliesModule>();
}

so the application needs to know something (the modules) of the assemblies and dependends on them.

Of course you are free to develop an elaborate scheme how to automatically load the modules by reflection to your liking. For example the 'StandardKernel' in its default configuration will look for assemblies where the name begins with 'ninject.extensions.' and then load the modules which are contained in this assembly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM