1

I have some Mapped objects[Entities] in my domain-layer which needs to be used by my web service which exposes these mapped objects to outside world. Where is the correct place for these mapped object? How would you structure your mapped objects and where is their correct location?

My project is a MVC5 .NET project which uses entity framework6 and has the following layers :

UI+Application Layer Domain Layer ( Entities.MappedObjects is the place I have put the mapped object for now) Infrastructure Layer (Does All the plumbing and accessing to DB)

MHOOS
  • 5,146
  • 11
  • 39
  • 74
  • take a look at this answer http://stackoverflow.com/questions/21620048/where-should-i-put-automapper-code/21622108#21622108 – Ehsan Feb 22 '14 at 10:37

2 Answers2

1

If you followed the Code First approach, then your Domain Model objects (which are the most essential part of Domain Model) are same as Entities.MappedObjects.

So they belong to Domain Layer.

In Code First approach your object are persistence-agnostic while in Database First approach you lose the flexibility of clean modularization of your architecture, cause your Objects are simply database tables and you the persistence concerns leaks into other layers.

Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
  • So you mean if I have Person class as one of my entities the MappedPerson class (Trimmed down version of Person) will be in the exact location as the Person class itself? – MHOOS Feb 21 '14 at 16:24
  • I think that we didn't agree on a ubiquitous language :-), I thought you mean "Domain Objects mapped to database tables" by Mapped Entities while as I understood you've referred to DTO objects. If so, then Service Layer would be the right place I think. – Jahan Zinedine Feb 21 '14 at 16:32
  • 1
    Checkout http://stackoverflow.com/questions/5881872/ddd-how-the-layers-should-be-organized for a good explanation of layers involved in a DDD architecture. – Jahan Zinedine Feb 21 '14 at 16:35
0

If you are separating the model objects from the DTOs your web service expose, then your DTOs (your MappedObjects) should reside on the service layer and not in the domain layer.

If MappedObjects are your actual domain objects, and you don't mind leaking your domain to the "outside world" through the service, then they might be fine where you have them right now.

jnovo
  • 5,659
  • 2
  • 38
  • 56
  • My MappedObject is a trimmed-down version of the actual (should not contain all the data) object. Are you implying that these mapped objects need to be in the service part of the infrastructure layer or have their own dedicated layer called Service Layer? – MHOOS Feb 21 '14 at 16:30
  • No, imho you are mixing service and infrastructure. There is usually a service layer, which would correspond in this case to your web services and related stuff, such as `MappedObjects`. There is a bunch of cross-cutting stuff which is not a layer (thus the cross-cutting name), such as logging for instance, which is what you might be calling "plumbing". Also, the data base access would not go into infrastructure but into the data access layer. – jnovo Feb 21 '14 at 16:38