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.