I have a web application made in asp.net mvc and I use Ninject to bind interfaces.
At the moment I have this:
// Db Context kernel.Bind<DbContext>().To<DbEntities>().InRequestScope(); // Repositories - which are using instance of DbEntities kernel.Bind<ICustomerRepository>().To<CustomerRepository>(); kernel.Bind<IProductRepository>().To<ProductRepository>(); // Services - which are using instances of Repositories kernel.Bind<ICustomerService>().To<CustomerService>(); kernel.Bind<IProductService>().To<ProductService>();
I am linking a DbContext with DbEntities in RequestScope because I want to use the same DbContext in the same web request. After that, he should dispose of it.
But how should the other bindings be? How are they by default?
For example, an IProductRepository that has an instance of DbContext (which one per request) should also have InRequestScope() ?
IProductService has an instance of IProductRepository
How should the bindings be suitable for a web application? (and I do not overload the server memory)
source share