I'm developing an application with XPO/XAF and I need to manage photos together with some additional information.
This is the simplified (pseudo) code I use for my Photo entity:
public class Photo
{
public Photo()
{
CreationDate = DateTime.UtcNow;
}
private Image imageData;
public Image Data
{
get { return imageData; }
set
{
imageData = value;
// Current Impl: Use static code to create thumbnail
Thumbnail = ImageService.CreateThumbnail(value);
}
}
public Image Thumbnail { get; private set; }
public Guid Id { get; }
public DateTime CreationDate { get; private set; }
public string Description { get; set; }
}
The Photo entity is used in various other entities, e.g.
public class Inspection
{
public Photo Photo { get; set; }
}
public class User
{
public Photo Photo { get; set; }
}
Whenever the Data of the Photo is changed, the thumbnail should also be updated. My posted solution works, but it's quite ugly, isn't it?
And it is also not possible to implement a new requirement: It should be possible to specify (application-wide) the quality of the thumbnails based on the usage (e.g. higher quality for Inspection thumbnails, lower quality for User thumbnails).
In XAF I would implement this requirement with a ViewControllerViewController, reacting to changes of a Photo (taking the current 'owning view' into account). But this solution has some drawbacks:
1) Thumbnail property setter cannot be any longer private.
2) It's quite hard to (unit-)test, because additional code is required to setup the ViewController infrastructure.
3) A ViewController is only active if there is a view. But it's also possible to edit photos from a custom OData-Service. Of course I can/should move ImageProcessing code from the ViewController to an utility class/method, but I have to remember to call this code when using my OData Controllers.
4) When viewing/editing Photos from a generic listview, the ViewController does not know which quality setting to use (because right now, there is only a generic Photo class and no back-reference to the 'owner' exists). Of course it's possible to inherit various Photo classes (UserPhoto/InspectionPhoto/...), but does this make sense?
I think generating and persisting thumbnails is quite a common task, therefore I'm really interested your ideas. I also like concepts/ideas of DDD/rich-domain model, therefore I would like to know whether it's possible to adopt such concepts to my situation