You question is not so clear, either way:
You will also have to re-inject on every other controller with ninject.
Maybe you can have on your BaseController a method that handle binding with generics and call it when ever you need.
protected T BindModel<T>(T model, string sessionKey){
T account = (T)controllerContext.HttpContext.Session[sessionKey];
if (account == null)
{
account = _viewModelFactory.CreateAccountVm();//new Cart();
controllerContext.HttpContext.Session[sessionKey] = account;
}
return account;
}
or, you can inject it like the following:
Bind<AccountViewModel>().ToProvider<ViewModeProvider>().InRequestScope();
class ViewModeProvider: ViewModeProvider<AccountViewModel> {
protected override AccountViewModel CreateInstance(IContext context) {
//put the logic from above here
return account;
}
}
or
Bind<AccountViewModel>().ToMethod(
c => new AccountViewModel{/* your logic goes here*/}).InRequestScope();
or maybe I did not get you correctly