-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request scope objects are acting like singleton .Net core #50
Comments
Hi. I'm having problems recreating your issue. I have tried debugging through the sample app to see if I can reproduce your issue there, but I come up short. Can you give some more info, a test or a sample on this issue? What version are you using? |
I found the issue. It looks like the problem is Scoped dependencies don't work since the service locator is used from a singleton context. I'll try to find a solution, but for now, use Transient or Singleton for dependencies of the handlers. |
I checked in some code to show of how this can be solved. Commit: 6b469d3 |
When a new command is raised for each request, (e.g: CreateInventory request) commandhandler's corresponding dependent objects like DbContext, Repository are not being created newly even if they are registered in request scope using .Net core DI container. They are acting like singleton objects. For the first request they are getting created and for subsequent requests if they are being used outside the scope of handler like in controller methods they are getting created for each request but when it comes to the handler dependent objects are not being created newly and using the objects that are created when the first time handler is created.
The text was updated successfully, but these errors were encountered: