Singleton depenendency injected service depending on scoped injected service #63967
Unanswered
jhudsoncedaron
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We had this issue this past week where we discovered that a particular singleton service would die after several hours. On tracing it to the bottom we found the impossibility; the singleton service was receiving a scoped service as a dependency. The dependency injector just lets you do this.
The correct fix was as expected, pass the scoped dependency in from the controller (on each of the handful of method calls that cared) rather than the constructor of the service.
I'm left wondering if the dependency injector should have caught this mistake or not.
Basically it looked like this (boneheaded mistake):
This happened because the new guy missed it; the two services.Add lines were in the same function but not the same screen.
I'm just wondering if DI itself or an analyzer should have caught this; or on the flip side there's a real use for this construct.
Beta Was this translation helpful? Give feedback.
All reactions