so I'm currently working on an ASP.NET MVC web application that uses the Entity Framework, I also use Ninject for Injection Dependency.
So, at the moment, this is how I am registering my DbContext and Services with Ninject.
kernel.Bind<DbContext>().To<MyApplicationContext>().InSingletonScope();
kernel.Bind<IAccountService>().To<AccountService>().InSingletonScope();
kernel.Bind<IRegionService>().To<RegionService>().InSingletonScope();
kernel.Bind<IRoleService>().To<RoleService>().InSingletonScope();
I register them using InSingletonScope, which means that they will be created only once and used throughout the entire application life cycle (at least as I understand it).
Controllers
private IAccountService _accountService;
public MemberController(IAccountService accountService)
{
_accountService = accountService;
}
However, I have a deep feeling that this singleton area will cause problems in my web application, especially for the Entity Framework context, because it is single.
- , SQL Management Studio, - Entity Framework , (, - EF).
-
, InSingletonScope, EF, , :
IEntityChangeTracker
, , DbContext, AccountService, , , RegionService. , .
- , - ?
-
EDIT: InRequestScope ,
IEntityChangeTracker
( ) . , DbContext, ?!
FINAL EDIT: . , , , .