I am starting to use Ninject in my MVC5 code-first app. Here\'s my NinjectWebCommon.cs:
private static IKernel CreateKernel()
{
var kernel = new Stan
This may not answer the question. But I tend to use the IDbContextFactory that EF provides you with and do something like this:
public interface IDefaultContextFactory : IDbContextFactory {}
public class DefaultContextFactory : IDefaultContextFactory
{
private readonly Lazy lazyContext = new Lazy(() => new CMSContext());
public CMSContext Create()
{
return lazyContext.Value;
}
}
Then you just bind that, and when you need the context you can do something like this:
public class ExecutiveRepository : IExecutiveRepository, IDisposable
{
private readonly CMSContext context;
public ExecutiveRepository(IDefaultContextFactory contextFactory)
{
this.context = contextFactory.Create();
}
}
I believe @BatteryBackupUnit is correct, I would also consider using the above pattern for contexts.