【发布时间】:2019-12-02 20:54:16
【问题描述】:
我是域驱动设计的新手,所以我想询问有关使用聚合根的应用程序服务。
我有一个聚合根。
public class Product: AggreagateRoot{
publis int Id {get; set;}
publis string Name {get; set;}
public ICollection<Comment> Comments {get; set;}
public ICollection<Types> Types {get; set;}
}
cmets 和 Types 与 Product 相关。所以 Comment 或 Type 本身并没有任何意义。
所以我正在为产品创建一个应用服务。
public class ProductService {
public Product Create(ProductCommand command){
.....
...
}
public Product Update(ProductCommand command){
.....
...
}
}
我应该像下面这样在 ProductService 中添加创建和更新 Comments 和 Types 的方法吗?
public class ProductService {
public Product Create(ProductCommand command){
.....
...
}
public Product Update(ProductCommand command){
.....
...
}
public Comment Create(CommantCommand command){
var product = _context.Product.Find(command.ProductId);
product.Comments.add(new Comment(command.message));
_context.SaveChanges();
.....
...
}
public Comment Update(CommantCommand command){
var comment = _context.Comments.Find(command.Id);
comment.message = command.message;
_context.SaveChanges();
.....
...
}
}
或者我应该为评论和类型创建单独的服务吗?
【问题讨论】:
标签: design-patterns architecture domain-driven-design