Here is a service
public interface IFoodEstablishmentService
{
Task<int> AddAsync(FoodEstablishment oFoodEstablishment);
Task<int> UpdateAsync(FoodEstablishment oFoodEstablishment);
}
This is my normal implementation
public class FoodEstablishmentService : IFoodEstablishmentService
{
public async Task<int> AddAsync(FoodEstablishment oFoodEstablishment)
{
// Insert Operation
return result;
}
public async Task<int> UpdateAsync(FoodEstablishment oFoodEstablishment)
{
// Update Logic
return result;
}
}
This is how i use it
IFoodEstablishmentService oFoodEstablishmentService = new FoodEstablishmentService();
oFoodEstablishmentService.AddAsync(oFoodEstablishment);
But wait what if I might need to pass my insert logic through queue rather than directly to server, wait for insert operation to complete and then return result, rather pass on queue and then the queue worker handles those operation?
So instead of messing everything, I just implement another class with same interface
public class FoodEstablishmentQueueService : IFoodEstablishmentService
{
public async Task<int> AddAsync(FoodEstablishment oFoodEstablishment)
{
// Insert Queue Operation
return result;
}
public async Task<int> UpdateAsync(FoodEstablishment oFoodEstablishment)
{
// Update Queue Logic
return result;
}
}
And this is how I use it, isn't it easy without breaking anything, and with DI Container as stated on earlier answer even works better
IFoodEstablishmentService oFoodEstablishmentService = new FoodEstablishmentQueueService();
oFoodEstablishmentService.AddAsync(oFoodEstablishment);
I guess don't choose for best pattern rather start with any and then slowly you will have need for something more and then pattern comes to play in addition Repository pattern or generic repository pattern might not be ideal pattern for large scale application where select logic is beyond selecting just a model data. Please search for CQRS pattern.