Zwiebelarchitektur - Service Layer Verantwortung

Ich lerne jetzt seit mehr als 2 Wochen Zwiebelarchitektur von Jeffrey Palermo. Ich habe ein Testprojekt wie folgt erstelltdieses Tutorial. Während des Studiums bin ich gestoßendiese Frage zu SO. Laut akzeptierter Antwort eine Personnwang schlägt vor, dass Methoden wie GetProductsByCategoryId nicht im Repository und andererseits sein solltenDennis Traub schlägt vor, dass es in der Verantwortung des Repository liegt. Was ich mache ist:

Ich habe ein Allgemeines Repository inDomain.Interface in dem ich eine methode habeFind :

public interface IRepository<TEntity> where TEntity : class
{
     IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> filter = null);
     .......
     .......
     .......
}

Dann habe ich eine erstelltBaseRepository imInfrastucture.Data:

public class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class
{
     internal readonly DbSet<TEntity> dbSet;
     public virtual IEnumerable<TEntity> Find(
            Expression<Func<TEntity, bool>> filter = null)
     {
            IQueryable<TEntity> query = dbSet;

            if (filter != null)
            {
                query = query.Where(filter);
            }
            return query.ToList();
     }
}

Und ich habe einekonkretes Endlager imInfrastructure.Data

public class ProductRepository : RepositoryBase<Product>, IProductRepository
{
      public ProductRepository(MyDBContext context)
           : base(context)
       {         

       }
}

Was ich jetzt in meinem Service-Layer mache, ist Repository in den Service injizieren und anrufenRepository.Find für Methoden wieGetProductsByCategoryId. Mögen :

public class ProductService : IProductService
{
     private readonly IUnitOfWork _unitOfWork;
     private readonly IProductRepository _productRepository;

     public ProductService(IUnitOfWork unitOfWork, IProductRepository productRepository)
     {
          _unitOfWork = unitOfWork;
          _productRepository = productRepository;
     }

     public IList<Product> GetProductsByCategoryId(int CategoryId)
     {
          // At the moment, My code is like this:
          return _productRepository.Find(e => e.CategoryId == CategoryId).ToList();

          // My confusion is here. Am I doing it right or I need to take this code to 
          // ProductRepository and call _productRepositoy.GetProductsByCategoryId(CategoryId) here instead.
          // If I do this, then Service Layer will become more of a wrapper around repository. Isn't it?
          // My question is : What exactly will be the responsibility of the Service Layer in Onion Architecture?
         }
    }

Antworten auf die Frage(3)

Ihre Antwort auf die Frage