How to handle DBContext when using Ninject

Here’s how I would do your Ninject bindings,

kernel.Bind<DBContext>().ToSelf().InRequestScope();
kernel.Bind<ContentService>().ToSelf().InRequestScope();
kernel.Bind<IContentRepository>().To<ContentRepository>().InRequestScope();

This pattern should work fine in the example above with EF and Ninject.

Leave a Comment