My project is structured by services and repositories (all repositories share the db context). In one of my service levels, I have an asynchronous method that writes to the database using the repository. The web request will complete and delete the context before this method can use it. I tried to understand NamedScopes as indicated in this. I still do not understand how to implement this. I will show how my project is structured and hope someone can help me at the code level.
Handcuffs
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<EntityDatabaseContext>().ToMethod(context => new EntityDatabaseContext()).InRequestScope();
kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
kernel.Bind<IRepository<Account>>().To<Repository<Account>>().InRequestScope();
kernel.Bind<IAuthenticationService>().To<AuthenticationService>().InRequestScope();
}
Authentication Service uses constructor injection
public AuthenticationService(UnitOfWork unitOfWork, IRepository<Account> accountRepository){}
Method inside my AuthenticationService
//this is a background process
public Task SomeMethodAsync(string text)
{
//spin it off into a new task
return Task.Factory.StartNew(() => SomeMethod(text));
}
SomeMethod accountRepository. , , . , , NamedScopes , ?
, , ninject - .