作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 unitofwork 和 Repository 实现了一个可以正常工作的架构。我有一个名为 Product 的实体,我在 Controller 中使用 ProductService 进行 CRUD 操作。
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);
}
}
现在我写了一个包含所有方法的服务基础并写下:
公共(public)接口(interface) IProductService:ServiceBase
我不想再写这些方法了。
最佳答案
首先,这个话题似乎根本没有任何具体的问题。
假设您的意思是让您的接口(interface)实现一个抽象类:
你有什么理由不只使用抽象类吗?您可以使用默认方法创建一个抽象类,并且可以将先前包含在您的接口(interface)中的方法声明为抽象方法。你可以在那里看到一个这样的例子:
如果这不能回答您的问题,请提供更多信息,以便我们了解您在此尝试实现的目标。
谢谢。
关于asp.net-mvc - 如何在 ASP.NET MVC 中使用 UnitOfWork 和 Repository 架构中的 IService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37307509/
我是一名优秀的程序员,十分优秀!