我正在开发一个应用程序使用asp.net mvc,NHibernate和DDD。我有我的应用程序的控制器使用的服务层。一切都在使用Unity来注入依赖关系(ISessionFactory存储库中,服务器和服务器中的服务器存储库)并且工作正常。服务层重复我的存储库
但是,这是很常见的,我需要在服务的方法来获得唯一对象在我的仓库,像这样(服务类):
public class ProductService {
private readonly IUnitOfWork _uow;
private readonly IProductRepository _productRepository;
public ProductService(IUnitOfWork unitOfWork, IProductRepository productRepository) {
this._uow = unitOfWork;
this._productRepository = productRepository;
}
/* this method should be exists in DDD ??? It's very common */
public Domain.Product Get(long key) {
return _productRepository.Get(key);
}
/* other common method... is correct by DDD ? */
public bool Delete(long key) {
usign (var tx = _uow.BeginTransaction()) {
try
{
_productRepository.Delete(key);
tx.Commit();
return true;
} catch {
tx.RollBack();
return false;
}
}
}
/* ... others methods ... */
}
此代码是正确的DDD?对于每个服务类,我有一个存储库,并且对于每个服务类需要我为一个实体做一个“获取”方法?
谢谢你们
干杯