Ninject caching an injected DataContext? Lifecycle Management?
- by awrigley
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?