IDisposable Constructor Injection
If I new up a class to inject via constructor injection which has an IDisposable object, does the class receiving the IDisposable parameter need to implement IDisposable?
eg:
Does player need to be
using var player
?2 Replies
If the class stores the injected thing in a field and effectively takes ownership of that disposable, then yes it should implement IDisposable itself.
And you would probably remove the other using (the first line of your code example) because you don't want two pieces of code disposing the same thing possibly at different times.
Thank you!