c# - Aggregate repository/service pattern -


i have following example wondering when split out other repositories. have list of products have categories, product lines , product types. can add, delete , edit of them, service doing much?:

public interface iproductservice : iservicebase {     void deleteproductcategory(int productcategoryid);     ienumerable<productcategory> getallproductcategories();     ienumerable<productcategory> getdisplayedproductcategories();     productcategory getproductcategory(int productcategoryid);     productcategory saveproductcategory(productcategory productcategory);      void deleteproductline(int productlineid);     ienumerable<productline> getallproductlines();     ienumerable<productline> getdisplayedproductlines();     productline getproductline(int productlineid);     productline saveproductline(productline productline);      void deleteproducttype(int producttypeid);     ienumerable<producttype> getallproducttypes();     ienumerable<producttype> getdisplayedproducttypes();     producttype getproducttype(int producttypeid);     producttype saveproducttype(producttype producttype);      ienumerable<product> getproductsbycategory(int productcategoryid);     ienumerable<product> getproductsbyline(int productlineid);     ienumerable<product> getproductsbytype(int producttypeid); } 

i using repository pattern, have inject repositories well:

public productservice(         irepository<product> productrepo,         irepository<productcategory> productcategoryrepo,         irepository<productline> productlinerepo,         irepository<producttype> producttyperepo,         ivalidationservice validationservice,         iunitofwork unitofwork         )         : base(validationservice, unitofwork)     {         enforce.argumentnotnull(productrepo, "productrepo");         enforce.argumentnotnull(productcategoryrepo, "productcategoryrepo");         enforce.argumentnotnull(productlinerepo, "productlinerepo");         enforce.argumentnotnull(producttyperepo, "producttyperepo");          this.productrepo = productrepo;         this.productcategoryrepo = productcategoryrepo;         this.productlinerepo = productlinerepo;         this.producttyperepo = producttyperepo;     } 

seems me lot of dependencies. when/how should split them out?

personally have desire create basic generic service class , inherit few services it. this

public abstract class generalservice<t> {     private irepository<t> _repository;     public generalservice(irepository<t> repository)     {         _repository = repository;     }      public abstract void delete(int id);     public abstract ienumerable<t> getall();     public abstract ienumerable<t> getdisplayed();     public abstract t get(int id);     public abstract t save(t t);      public abstract ienumerable<product> getproducts(int id); }  public interface irepository<t> {     ... } 

and

public class productservice : generalservice<product> {     ... }  public class productlineservice:generalservice<productline> {     ... } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -