How to invoke a new Ninject context on a Timer task? Having a hard time configuring ninject scope to unitofwork. If I set as InRequestScope() it doesn't work on non request tasks. So I set up like below so that I can get InThreadScope for tasks:
kernel.Bind<IUnitOfWork>().To<myEntities>().InScope(ctx => HttpContext.Current ?? StandardScopeCallbacks.Thread(ctx));
But that way, when I set up a timer
Timer timer = new Timer(_ => DelayedDisconnect(chatUser.User.AuthorizationId), null, TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(-1));
the dbContext doesn't refresh with the new database values.
public void DelayedDisconnect(string authorizationId)
{
var myChatUser = GetChatUserByClaimedIdentifier(authorizationId);
if (!myChatUser.ChatClients.Any()) // old state (doesn't reflect database changes from 10 seconds ago).
So...How to invoke a new Ninject "context" to reflect current state / db values?