I use Ninject for my IoC Container in most of my projects, at this time.
When setting up my infrastructure layer, it is pretty common that I’ll need to send along some value that isn’t the default.
To send a non-default class, such as the case where I want to send a DbContext other than the default, I use this method:
//MyEntitiesClass is generated by the EDMX in my domain layer. kernel.Bind<IMyRepository>().To<MyRepository>() .WithConstructorArgument("dbContext", kernel.Get());
//assume myConnString has been loaded from web.config just before this is called. kernel.Bind<IMyRepository>().To<MyRepository>() .WithConstructorArgument("connString", myConnString);
That is pretty simple.