For background, i have a Data layer and Service layer loosely based on Rob Conery's Storefront model and like Rob's, many of my domain objects and chained with LazyList<>
's and LazyItem<>
's to make use of the deferred execution that Linq2Sql provides given that my Lazy*
types utilise IQueryable<T>
rather than this awesome delegate approach.
So i have an object graph like this (basically, each Activity should have a photo gallery of many images- thumbnails and full size photos):
latest3Activities[0].Gallery.Images.Inner[1].FullImage
The Gallery
type has an Images property of LazyList<PhotoGalleryImage>
and so the IList<PhotoGalleryImage>
from that LazyList is the Inner
you see. Each PhotoGalleryImage
item has a FullImage
property and a Thumbnail
property, both of type Image
.
The idea is that the full rez uploaded photo is stored in the PhotoGalleryImage.FullImage
property and initially, the Thumbnail
property is Null
.
What i'm after is this: when the Thumbnail
property is accessed for the 1st time, if it is Null
i want my Service layer to generate the Thumb, persist it to the DB, then return the Image
instance which is the smaller photo. I have all the code to create the thumbnail from the full size image, so that's not the question here.
What i cant figure out is how to catch the first access of the Thumbnail
property (in my IQueryable<>
architecture context) and then have the Service layer do the resizing and not the Repositories (DAL). I strongly feel that the Service (business) layer should be responsible for this functionality decision but i don't see how to make it work.
Currently i'm thinking the mapping from my domain classes in the repositories to the Linq2Sql classes would be a good place to identify this 'first access' i refer to, but i dont then see how a lower tier can then call up into the Service layer and perform the shrink (or even if it can, that it should).
Maybe my design constrains me to have the Repos do the conversion. Maybe i shouldn't want the Service layer to perform this logic at all. Maybe my design is just so horrid that i really shouldn't be facing this mess at all.
Pls help. All feedback is appreciated.