William
William

Reputation: 8067

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 breakpoint 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?

Upvotes: 0

Views: 665

Answers (1)

William
William

Reputation: 8067

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.

Upvotes: 1

Related Questions