I am working on a new three-layered .net/WPF application. The application will do a lot more than just CRUD, but it does CRUD too. I'm finding that there's a ton of redundant work that needs to be done when setting up a new CRUDdy entity; say, a Person
:
- In the data access assembly, create a
PersonDocument
class that is structured and marked up with attributes in a way that allows our in-house document storage system to persist it - But I don't want to expose
PersonDocument
to the upper layers since that would leak information about the persistence mechanism. So the DAL also needs a publicIPerson
and code to adapt aPersonDocument
into anIPerson
- The DAL needs to expose a
PersonRepository
so the upper layers can do CRUDs withIPerson
s - The business layer needs to provide information about persons to the presentation layer, but the presentation layer isn't supposed to know about the data access layers or it types. So the BL assembly needs its own
IPerson
. This is probably not exactly like the DALIPerson
--in particular, the DALIPerson
is going to be almost 100% anemic (data only), while the BLIPerson
will contain a bunch of operations relating to the business actions you might want to take with a person. But it will be pretty close, and with some simple entities, perhaps exactly the same. - More mapping code will be needed to go back and forth between a DAL
IPerson
and a BLIPerson
- The BL will need its own
PersonRepository
over BLIPerson
s for use by the presentation layer
Now imagine that I decide I want to start tracking the age of every person I store. I'll need to:
- Add an age property to the DAL's person document
- Add an age property to the DAL's
IPerson
and its implementation(s) - Update the code that translates a
PersonDocument
into a DALIPerson
- Update the code that translates a DAL
IPerson
into aPersonDocument
- Add an age property to the BL
IPerson
and its implementation(s) - Update the code that translates a DAL
IPerson
into a BLIPerson
- Update the code that translates a BL
IPerson
into a DALIPerson
- Finally, I can update the databindings in presentation to display age
Something like AutoMapper could maybe ease the pain in 3, 4, 6, and 7 if I invest the time to learn to use it, but the amount of work involved here still seems to be telling me I have a bad design. Is this just the way it goes with 3-layer architecture, or am I missing the point?