Thursday, June 13, 2019

AutoMapper mappings up in the UI project!

Yes, this is a thing. I'm not in love with it but I've seen it in two different projects now. The reason you have to go there in an onion architecture setup is that you want to map from a type that is only in the infrastructure project to a type in the core project that doesn't know about the infrastructure's type. Don't do this. Put the type you want to hydrate from a database call in the core and if you have to map it some something else in the core you may keep the whole of the mapping in the core. If you are having core objects hydrate DTOs for the UI, why can't the DTOs also just be in the core? The original idea behind the onion architecture was to make the core as fat as possible. When stuff bleeds out to other layers I wince/cringe. Anything that is plain Jane C# should be a candidate for core citizenship and really only external dependencies, UI machinery, exposed UI endpoints, and unit tests should ever live in other layers.

No comments:

Post a Comment