I have a question, and I\'m going to tag this subjective since that\'s what I think it evolves into, more of a discussion. I\'m hoping for some good ideas or some thoug
You actually came up with a very dirty solution: your IService
contract violates the SRP, wich is a big no-no.
What I recommend is to distinguish so-called "singleton" services from so-called "prototype" services. Lifetime of "singleton" ones is managed by the container, which may query at runtime whether a particular instance implements IDisposable
and invoke Dispose()
on shutdown if so.
Managing prototypes, on the other hand, is totally the responsibility of the calling code.