5

I'm designing an application with DDD. I'm moving from flat POCO objects to strong domain models, so my question is:

Would I have to call my basic CRUD operations (located in my repository layer) from controllers directly, without passing through the domain layer? I can't see any added value to doing that, but I'm not sure if it's inside the DDD practices make that direct call.

Robert Harvey
  • 200,592
Franco
  • 153

3 Answers3

6

The typical entry point for this in DDD is an Application Service. Application services orchestrate calls to repositories and domain objects. They also know about the current execution state and often control the overarching business transaction through a unit of work that is committed at the end of the service method.

For example :

Create new domain object
Add it to Repository
Commit UoW

or

Get domain object from Repository
Modify it
Commit UoW

etc.

The application service can be called from a Controller. In some implementations it is the controller, when people don't want to bother an additional abstraction layer. But that can lead to a Fat Controller.

my basic CRUD operations (located in my repository layer)

While C, R and D are part of a Repository interface, U doesn't have to if you have a Unit of Work. Update of all changed domain entities in the UoW will be done automatically on UoW.Save().

guillaume31
  • 8,684
0

Would I have to call my basic CRUD operations (located in my repository layer) from controllers directly?

No, there's nothing that forces or requires you to do that. You can add as many layers between the controller and your database as you wish, or split it into separate repositories if you like.

Robert Harvey
  • 200,592
0

Would I have to call my basic CRUD operations (located in my repository layer) from controllers directly, without passing through the domain layer?

I think this is ok. Just take a note, that if you have your application split into three layers (UI, domain logic and storage), in your case UI will depend both on domain logic and storage layers.

If persistence is used only from domain logic layer, UI layer is left depending on domain logic layer only.

Without seeing your actual application it's hard to say, if that is good or bad.