vendredi 6 octobre 2017

Correct Implementation of the repository service pattern for big model

I have a dilema implementing the repository service pattern in my C# WPF MVVM project where I have a big dataset in my model.

I used EntityFramework database first where I have created about 40 entities, so my model is quite large and for me it does not make sense to implement 40 different repositories, due to this I made use of the generic repository service pattern.

My Repository looks like the following:

  public interface IEntityRepository<T> : IDisposable where T : class
  {
    IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
    IEnumerable<T> getEntities();
    T RetrieveEntity(int entityID);
    void CreateEntity(T entity);
    void UpdateEntity(T entity);
    void DeleteEntity(T entity);
    void Save();
  }

And here is the signature of the class implementing the methods.

    public class EntityRepository<T> :
     IEntityRepository<T> where T : class
    {
      private DbContext context;
      public EntityRepository(DbContext context)
      {
        this.context = context;
      }          

       .....

    }

My question now is, how would the service look like so that I don't have to implement it for every single entity in my model. I'm looking for something like that I can dymanically create the service by the type name of the entity.

Does anyone knows a solution for my problem? Thanks!

Aucun commentaire:

Enregistrer un commentaire