Instead of using this interface:
public interface IStartable
{
void Start();
void Stop();
}
Usually I just make the constructor of the object run the Start () code and implement IDisposable so that the dispose method executes the Stop () code.
Is this just a matter of style? Or did I miss something important without having something like IStartable? All I see is additional complexity because you have to maintain its start / stop state.
What are the advantages and disadvantages of using start / stop vs using ctor / dispose, especially in the context of the IoC / DI container?
EDIT: Great answers, you convinced me to use the interface for startup objects. I can’t decide which answer is better, so I agree with the one who has the most votes in 24 hours.
source
share