I would like to organize my Ninject bindings by separating them into Ninject modules. However, I have more than one application that would be using these modules. One of them is an ASP.Net MVC application, another is a console application, another a windows service, etc, etc. In the MVC app, I would like to use the InRequestScope
scope binding, but in another application (that references my core assemblies where the Ninject modules are located) I would like to use a different scope binding. Is this possible?
As my infrastructure grows and the registration for all of my bindings becomes very large and verbose, I end up repeating these bindings in several different composition roots - the only difference between them being the lifetime scope of each binding. I'd really like to make this more DRY.
What would be ideal is the following (pseudo-code):
Core assembly which multiple apps reference
public class MyModule : NinjectModule {
public override Load(){
Kernel.Bind<IMyType>().To<MyType>();
}
}
In the MVC application
kernel.Load(new MyModule())
.Configure(p => p.UseInRequestScope);
In another application
kernel.Load(new MyModule())
.Configure(p => p.UseInTransientScope);