Ninject caching an injected DataContext? Lifecycle Management?
Posted
by
awrigley
on Stack Overflow
See other posts from Stack Overflow
or by awrigley
Published on 2010-12-23T08:30:55Z
Indexed on
2010/12/23
8:54 UTC
Read the original article
Hit count: 221
I had a series of very bizarre errors being thrown in my repositories. Row not found or changed, 1 of 2 updates failed... Nothing made sense.
It was as if my DataContext instance was being cached... Nothing made sense and I was considering a career move.
I then noticed that the DataContext instance was passed in using dependency injection, using Ninject (this is the first time I have used DI...). I ripped out the Dependency Injection, and all went back to normal. Instantly.
So dependency injection was the issue, but I still don't know why. I am speculating that Ninject was caching the injected DataContext.
Is this correct?
Is there a way of configuring the lifecycle management of injected parameters?
If so, what would be the best configuration to use to have the DataContext behave like a normal DataContext, ie, no caching across requests?
© Stack Overflow or respective owner