Short best practice question: If an object A is injected into another object B, should then object B implement IDisposable and dispose A when B is disposed?
If you're referring to the dependency injection pattern, I think it depends on the knowledge in Object B about the implementation of Object A. The reason for doing dependency injection like this is usually because you do not know on beforehand how Object A will be implemented and whether it requires IDisposable. The only thing you know is the interface.
Adding this behavior would result in tighter coupling between the two classes, IMO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With