Here's where I'm up to.
I have a generic Repository class Repository<TKey, TValue>
. It has the usual Repository pattern methods.
Each Repository takes an IContext<TKey, TValue>
in its constructor which provides the persistence for the repository.
I have specialised repositories which are composed of a generic Repository and then methods tailored to repository actions that are specific to the specialised object. So if I had a specialised repository for Kitten objects, It would have methods to ClimbTree (probably taking a tree object) but not a BuryBone(Bone bone) method. The point I'm making badly is It creates an association between the kitten and its tree which needs to be persisted. void CleanWhiskers()
might be a simpler example. This sets the Kittens whiskers to clean.
So I'm now thinking of a scheme for related child objects persistence and starting to wonder if I'm already going a bit wrong.
I started with slightly ugly methods on the repository to create child objects. So Kitten repository would have a method CreateFurBall()
which would add a FurBall object to the Kitten's FurBall collection AND add a Furball to the FurBall Repository to be persisted (Actually the same object).
I've now changed to a system where I have something akin to an ObservableCollection which notifies its parent repository when a POCO is added. So I can just create a POCO furball and added it to the collection which would then be automatically registered with the furball repository.
First off I'll have nHibernate implemented in the contexts, I think this maps fairly well. This is a really open question, for anyone that's been down this route before, can you see anything that makes you go "STOP!!"