How should I generate the sketch?
For the background I have a data layer and a service layer based on the Rob Conery Storefront model and like Rob, many of my domain objects and are chained LazyList<>
and LazyItem<>
to use the deferred execution that Linq2Sql provides, given that my types Lazy*
are using IQueryable<T>
, and not this awesome delegate approach .
So, I have a graph of objects like this (basically, each operation should have a photo gallery of many images - thumbnails and full size photos):
latest3Activities[0].Gallery.Images.Inner[1].FullImage
The type Gallery
has an Images property LazyList<PhotoGalleryImage>
, so IList<PhotoGalleryImage>
from this LazyList is the Inner
one you see. Each element PhotoGalleryImage
has a property FullImage
and a property Thumbnail
, both types Image
.
The idea is that the full rez uploaded photo is stored in the property PhotoGalleryImage.FullImage
and initially the property Thumbnail
has a value Null
. What I need after that: when the property is Thumbnail
accessed for the first time, if it is Null
, I want my service layer to generate Thumb, save it to the DB, then return an instance Image
which is the smaller photo. I have all the code to create a thumbnail from a full size image, so no question here.
What I can't figure out is how to catch the first property access Thumbnail
(in my architecture context IQueryable<>
) and then use the service layer and not the repositories (DAL). I strongly feel that the service layer (business) should be responsible for this feature-wise solution, but I don't see how to get it to work.
Currently I think that mapping from my domain classes in the stores to the Linq2Sql classes would be a good place to identify this "first access" that I am accessing, but I don't see how then the lower layer can call to the service layer and execute compression (or even if possible that it should).
Perhaps my project is limiting me to what Repos does the transformation. Maybe I don't want the service layer to do this logic at all. Perhaps my design is so awful that I really shouldn't be facing this mess.
Pls help. All feedback is appreciated.
a source to share
The point of lazy init is to defer resource allocation since you don't know when or when you need it.
It doesn't make sense in your case: as soon as the image is loaded, the server needs a thumbnail - the user wants to see the new image right away, right? Therefore, deferring sketching has no positive ROI.
a source to share
I had a very similar problem a couple of months ago with uploaded images, sketching and asking where the code should go to create the thumbnails. I also really felt that this code belonged to the service layer (not least because the storage for image and thumbnail files was abstracted in the frontend and injected through the IOC container, and I didn't want any dependency injected into my domain layer ).
In the end, I created all the thumbnails at the point where the image is loaded via calls to the service layer from the UI controller. I tried to create domain level images before this. For this I used a template in which when the domain layer needed to create the image it would raise an event that was connected to the service layer. The service layer then passed the storage interface instance back through event arguments to the domain layer so that the domain layer could store the image. It was very loosely based on some ideas from Udi Dahan's blogin which I came across using events in the domain model as a way to use logic in a service layer. Unfortunately, I can't find a link to the Udi site, but it's in there somewhere. It never felt right anyway - it seemed to be tightly connected along a different route, so I went back to creating the thumbnails created at the time the image was loaded through the service layer. However, perhaps in your case, you could use the idea of events from the domain level to invoke logic at the service level. I'm sure there is a lot of value in the idea itself, it just doesn't quite match what I'm doing.
a source to share