Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Which lifestyle to use for a DbContext? #792
I'm having a bad experience with a simple injection, I can't understand why my
I have my
I have a
In the first request, everything seems correct. When the second request is made it seems that it returns the same value even if it is changed in the database manually.
Is this some kind of cache?
Is it the type of record I'm using "Singleton" that is causing this behavior?
I was able to solve using
More with my research I saw that it is not indicated to use
I tried to change to Scoped but I get the following error
This exception was originally thrown at this call stack:
Hi @srburton, thank you for choosing Simple Injector.
Before you continue your quest in exploring Simple Injector and Dependency Injection, I can advise reading some of the fine documentation on DI and Simple Injector. I would suggest the following material in this order:
After reading this, you should have an idea about DI in general, and lifestyle management in Simple Injector, and what the caching behaviors are of the different lifestyles that Simple Injector comes with out of the box.
This, however, doesn't directly give you an answer on which lifestyle to use on which component, e.g. your
To understand what lifestyle is best for a DbContext, here are some pointers:
Good luck with your quest. If you have any questions after reading the provided information, feel free to ask.