-
Notifications
You must be signed in to change notification settings - Fork 318
How to dispose top-level IServiceProvider #338
Comments
Moving this to Backlog as we are not planning to make any changes for this at this time. |
What about an answer and/or close it instead? |
Nope 😄 |
I don't get it. Is that the answer? How does that relate to this? I don't really care about the interface, but there has to be some way to get a hold of the concrete type to call dispose on it, without resorting to casting etc.? |
Yeah not sure what @davidfowl is talking about there... But the answer for now is that unfortunately we don't have a good answer on this. I think creating a scope immediately is an acceptable workaround in the meantime. This is certainly something we can reconsider. |
We'd have to expose the concrete type (which we were trying to avoid) from BuildServiceProvider |
@Eilon we can consider this for 2.0. Make a breaking change to the return value of BuildServiceProvider and make the internal |
Let's do another fun DI triage 😄 |
Since
IServiceProvider
doesn't implementIDisposable
, andServiceProvider
(which does implement it) is internal, how are you supposed to dispose a "top-level service provider", i.e. the result of callingIServiceCollection.BuildServiceProvider()
?I could of course do a
(provider as IDisposable)?.Dispose()
, but it would be nicer if the interface implementedIDisposable
. That way it would work better with generic constraints etc.I understand that there's little to do with the interface itself, since it's an old interface that's been reused, but would it be possible to add a separate one?
Something along the lines of
I think I've gotten around the problem by immediately creating a scope, which is disposable, and use its provider, but I don't think it's a good solution.
What was the reasoning for using the existing interface? And why is everything internal? 😝
The text was updated successfully, but these errors were encountered: