❔ EF Core Query filters and DbContext lifetime
Hey!
To my project,
Using jwt's which contains the users id, after normal auth etc run a middleware runs that will pull data from the database (injecting a DbContext) and create a Identity and add it to the HttpContext.
Now my DbContext is using query filters, those query filters are configured by data from the HttpContext which was modified by my middleware.
The issue is that since my scoped DbContext was already injected in the middleware it was configured with HttpContext data before it was modified with the extra information.
Whats the solution here? I would prefer keeping my DbContext scoped, but the only solution I found so far would be changing it to transient.
The query filter reads from properties in my DbContext (using a factory etc), would it be bad practice to manually assign the values I got from the database in my injected DbContext?
3 Replies
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.bump
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.