Skip to content
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

Closed
jyothi530 opened this issue Sep 17, 2017 · 3 comments
Closed

Request scope objects are acting like singleton .Net core #50

jyothi530 opened this issue Sep 17, 2017 · 3 comments

Comments

@jyothi530
Copy link

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.

@gautema
Copy link
Owner

gautema commented Sep 18, 2017

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?

@gautema
Copy link
Owner

gautema commented Sep 18, 2017

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.

@gautema
Copy link
Owner

gautema commented Sep 20, 2017

I checked in some code to show of how this can be solved. Commit: 6b469d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants