【问题标题】:DDD Where to put image conversionDDD图片转换放在哪里
【发布时间】:2011-05-26 17:30:32
【问题描述】:

我有以二进制格式获取图像的应用程序。然后此应用程序必须将此图像转换为特定尺寸并将两种形式(原始和特定)保存到磁盘。在这种情况下,应用程序也必须将有关此图片的信息存储在数据库中。

转换的逻辑放在哪里:在应用层、领域层或基础设施层?

【问题讨论】:

    标签: architecture domain-driven-design


    【解决方案1】:

    除非您的领域是关于转换图像,否则您应该将转换逻辑放入基础架构层。

    类似这样的:

    //domain
    public class Image{
      public Image(string fileName){
        FileName=fileName;
      }
      public string FileName{get;private set;}
    }
    
    //infrastructure
    public class ImageConvertor:ICanConvertImages{
      public byte[] BmpToJpeg(byte[] img){
        throw new NotImplementedException("haa haa");
      }
    }
    
    //application
    var bmpImg=PullBytesFromNowhere();
    var jpegImg=convertor.BmpToJpeg(img);
    var fileName=SaveToFile(jpegImg);
    var image=new Image(fileName);
    

    【讨论】:

      【解决方案2】:

      嗯 - 可能是这个问题的重复?看看你的想法:convert of the object (image) to another object (Byte) in three layers(3-tier)

      【讨论】:

        【解决方案3】:

        «Service» 似乎很适合您的上下文: http://dddcommunity.org/node/125

        【讨论】:

        • 是的,但是该服务放在哪里?在应用程序、域或基础设施层?
        猜你喜欢
        • 1970-01-01
        • 2014-02-16
        • 1970-01-01
        • 1970-01-01
        • 2011-03-08
        • 1970-01-01
        • 2017-01-29
        • 2017-11-14
        • 2012-11-28
        相关资源
        最近更新 更多