lundi 10 septembre 2018

Is it a good design to resolve Concerte classes with Generic Intefaces for Dependency Injection?

Is it a good pattern to a have a Generic Interface to implement the Concrete classes and use the generic interface to resolve in container.
My concern is does it breaks the Single responsibility principle or is it tightly couples the implementation.

For example

  //Base Generic Interface
  public interface IBaseServiceCrud<T>
    {
    T Get(string key);
    bool Create (T entity);
    bool Delete(T Entity);
    }

   // Implement Concrete Class with Base Interface 
    public class Order : IBaseServiceCrud<Order>
    { }
    public class Product: IBaseServiceCrud<Order>
    { }


   //Or Should we have a interface specific to each service
   public interface IOrder: IBaseServiceCrud<Order>
   {}

 //And then Implement by Concrete Class
  public class Order : IOrder
  {}

In DI container support resolving Generic Interface, but my concern is it a good practice to resolve based on Generic interface.

Aucun commentaire:

Enregistrer un commentaire