3

I implement an architecture with unitofwork and Repository that worked correctly. I have a entity that is called Product and I Use ProductService in controller for CRUD operetioan.

 public interface IProductService
{
    IList<Product> GetAll();
    Product GetById(int id);
    void Create(Product product);
    void Update(Product product);
    void Delete(int id);
}

public class ProductService : IProductService
{
    private IRepository<Product> _productRepository;

    public ProductService(IRepository<Product> productRepository)
    {
        _productRepository = productRepository;
    }

    public IList<Product> GetAll()
    {
        return _productRepository
            .GetAll()
            .ToList();
    }

    public Product GetById(int id)
    {
        return _productRepository.GetById(id);
    }

    public void Create(Product product)
    {
        _productRepository.Create(product);
    }

    public void Update(Product product)
    {
        _productRepository.Update(product);
    }

    public void Delete(int id)
    {
        _productRepository.Delete(id);
    }

}

Now I write a Service Base that included All Method And write this:

public interface IProductService:ServiceBase

I do not want to write these methods again.

Bygonaut
  • 29
  • 11
Mohsen Zahedi
  • 651
  • 2
  • 10
  • 28

1 Answers1

1

First of all, this topic doesn't seem to have any specific question at all.

Assuming you mean to have your interface implement an abstract class:

Is there any reason you don't use the abstract class only? You could make an abstract class with the default methods and the methods that were previously included in your interface could be declared as abstract methods. You can see an example of this there:

Similar question

If this doesn't answer you question, please provide additional information so we can understand what you are trying to achieve here.

Thanks.

Community
  • 1
  • 1
DereckM
  • 274
  • 2
  • 11