相关疑难解决方法(0)

域对象和服务

这个问题中有人回答 "你永远不会让域对象实现自己调用服务!".这个陈述是DDD的一个严格的快速规则,还是取决于您自己的应用程序和架构?

举例:

举个例子,我们假设我们UserImage的模型中有一个对象,它由用户从上传的图像中填充.然后我们假设我们可以将此图像提交给可识别拇指打印的第三方服务,Guid如果找到匹配则返回.

public IThumbPrintService {
    Guid FindMatch(Bitmap image);
}

public class UserImage {
    public Bitmap Image {get; set;} 
    public Guid ThumbPrintId {get; set;}
    public bool FindThumbPrintMatch() {
       // Would you call the service from here?
       ThumbPrintId = _thumbPrintService.FindMatch(this.Image);
       return ! ThumbPrintId.CompareTo(Guid.Empty);
    }
}

public class RoboCopUserImageService : IUserImageService {
     // Or move the call to a service method 
     // since it depends on calling a separate service interface
     public bool FindThumbPrintMatch(UserImage …
Run Code Online (Sandbox Code Playgroud)

domain-driven-design

23
推荐指数
1
解决办法
5255
查看次数

标签 统计

domain-driven-design ×1