Closed WangFeng2333 closed 2 years ago
@WangFeng2333 A single DbContext
instance is recommended for each unit-of-work. That is, the context instance should be constructed, the work performed, and then it should be disposed.
In a web-app, this context instance lasts for the lifetime of the request by registering it as Scoped in the container. However, registering as Transient is also a valid option if there isn't a natural request scope or if multiple independent units-of-work are needed.
Dear guys,
I am facing an issue that we have an asp.net webapi core 2.2 project with EF core 2.2. We are using default IOC framework to create the DBContext with Scope lifetime. And we have an Socket pipeline connect to our asp.net webapi service , I find that even we change the data by Web Front-end, the socket pipeline will always get the Old result( we are using FirstOrDefault to fetch the data ,it should not be the problem with first-level cache). So I infer , it might be because of that the Scope Lifetime DbContext , so I change it to Transient Lifetime . And it works! We get the modified record.
I have two questions: