I'm trying to define interfaces for services that should have methods like start, stop, Resume.
But some services can be asynchronous which needs to implement the same methods (start, stop and Resume) asynchronously. One more caveat here is asynchronous method also accepts cancellationToken
Problem Some services can start async and stop synch. By following ISP(Interface segregation principle). if we create a consumable interface i.e
public interface IStartable
{
void Start();
}
public interface IStopable
{
void Stop();
}
public interface IStartableAsync
{
Task StartAsync(CancellationToken cancel);
}
public interface IStopableAsync
{
Task StopAsync(CancellationToken cancel);
}
public interface IStartStoppable: IStartable, IStopable
{}
public interface IStartStoppableAsync: IStartable, IStopable
{}
As we can see above, it needs to create too many interfaces with various combinations.
Is there any better way of designing this, which is relatively simple and maintainable?
Aucun commentaire:
Enregistrer un commentaire