Ninject V2 InRequestScope: firing constructor on every request
I'm having a hard time with Ninject V2's InRequestScope() for managing a UnitOfWork.
_kernel.Bind<UnitOfWork>().To<SqlUnitOfWork>().InRequestScope();
I expect whenever I request the UnitOfWork via the container that the same object is always returned throughout the request. However, in the debugger I have a 开发者_如何学Pythonbreakpoint on the object's constructor and whenever a request is made to the container the constructor fires as though a new object is being created.
var uow = CreateKernel().Get<UnitOfWork>();
Has anyone had similar experiences as this or am I missing something critical?
Incase anyone else has this problem my issue was related to the global.asax file. I was manually storing the result of CreateKernal in a private variable. Changing to access the request's created kernal via the Kernal property of the base NinjectHttpApplication class sorted the issue.
精彩评论