DDD Where to put image conversion
I'm have application that gets image in binnary format. Then thi开发者_如何学编程s application must convert this image to specific dimmension and save both form (orginal and specific) to disk. In this case application must store info about this picture in database too.
Where put the logic of conversion: in application layer, in domain layer or maybe in infrastructure layer?
You should put conversion logic into infrastructure layer unless Your domain is about converting images.
Something like this:
//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);
Hmm - possibly a duplicate of this question? have a look and see what you think: convert of the object (image) to another object (Byte) in three layers(3-tier)
«Service» seems to be a good fit given your context: http://dddcommunity.org/node/125
精彩评论