donderdag 17 april 2008

How to seperate Domain and infrastructure logic?

Tags van Technorati: ,,

Today I struggled with the fact that some infrastructure code drippled into my domain while building the ORM features ourselves.

The problem was that I had to load a bunch of objects as a Tree Collection.  So the easy solution was to add an extra Id field to the class to store the parent/child object Id and after all where loaded, iterate an link to the correct solution.  Now I polluted my domain with some infrastructure fields (I had to add some more...).

Because we are already using the Windsor container as our dependency container and the dynamix Proxy Interceptors for lazy loading on the project, I thought about using the mixin functionality they offer.  I created an extra data object in the infrastructure layer and then wanted to 'mix' them.  Bummer, dynamic proxy 2 does not support this functionality (although ayende claims he added support for about a year ago)!

So I went for the second solution, much simpler in my opinion.  Instead of creating an seperate data structure to hold the extra data, I decorated my domain object.  My mapper object now creates the decorated objects (which are internal).  After I loaded all my objects into memory, the repository uses the extra data to build up the tree and voila we're done.  My domain remains mean, lean and clean, but I have the extra information at my disposal.

Till next time...

Submit this story to DotNetKicks

Geen opmerkingen: