Domain Driven Design - where should we put repositories?

user80855

I am putting together a new system and I would like to have a rich domain for it. However, I am stuck on a little detail I want to know more about.

Suppose I would have a class Customer, where do you actually persist a customer entity or aggregate root?

should it be the customer class that has the knowledge of persistence?

var myCustomer = CustomerFactory.CreateCustomer(id);
myCustomer.Name = ...
myCustomer.LastName = ...

myCustomer.Save()

in this case I would need to pass my repository of Customers into the customer class (either via the factory or some injection). Notice that I could not find a good example of this in the DDD book by Eric Evens.

Another way is keeping the customer free of knowing about persistence

var myCustomer = CustomerFactory.CreateCustomer(id);
myCustomer.Name = ...
myCustomer.LastName = ...

CustomerRepository repository = new CustomerRepository();
repository.Save(myCustomer);

Also I suppose I can have a service class that does it all together like this:

AddCustomerService service = new AddCustomerService(CustomerRepository repository)
service.AddCustomer(myCustomer);

just a little note: if I don't actually save in the customer class, I find that my customer class is nothing but properties, maybe with a little validation but nothing more. No real behavior is there. Behavior is moved either to service class or repositories used by the client...

Greg

I have a DDD project. There are 4 layers in this order (because I am not using WCF else there would be more):

1. UI
1.1 MVC4.csproj
... (Repository Interfaces)
... (Repository Implementations)

2. Service Layer
2.1 Service.cs 
...DTOs

3. Business Layer
3.1 DomainObjects.csproj

4. Data Access Layer
4.1 DAL.csproj (Entity framework 5)
... (Repository Interfaces)
... (Repository Implementations

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where to put security when using DDD - domain driven design

From Dev

Where to put general purpose serialization class in domain driven design?

From Dev

Domain Driven Design: Can Infrastructure or Repositories use Domain objects?

From Dev

Domain Driven Design: Can Infrastructure or Repositories use Domain objects?

From Dev

Is there a mismatch between Domain-Driven Design repositories and Spring Data ones?

From Dev

Is there a mismatch between Domain-Driven Design repositories and Spring Data ones?

From Dev

Where is the call to persistence in the domain driven design

From Dev

Where to find Domain Driven Design consultants?

From Dev

When we shouldn't use Domain-Driven Design approach?

From Dev

Should Entities in Domain Driven Design and Entity Framework be the same?

From Dev

How much realistic should be a model in domain driven design?

From Dev

Layers in Domain Driven Design

From Dev

Where does the message bus service live in Domain Driven Design

From Dev

Meteor: Where should we put common functions?

From Dev

Where should we put the cast in following situation

From Dev

Domain Driven Design - Domain or Security

From Dev

Access Control in Domain Driven Design

From Dev

Domain Driven Design and batch processing

From Dev

Implementing Domain Driven Design Cost

From Dev

Implementing Domain Driven Design Cost

From Dev

Domain Driven Design Bounded Context Domain Objects

From Dev

Domain Driven Design: infrastructure concern or domain concern?

From Dev

Domain Driven Design: infrastructure concern or domain concern?

From Dev

Domain Driven Design. Entity type design

From Dev

Implementing Paging and Sorting with Domain Driven Design

From Dev

Implementing Domain-Driven Design and Transactions

From Dev

Domain driven design repository implementation in infrastructure layer

From Dev

Domain Driven Design in Node.js Application

From Dev

Fetching associated aggregates in Domain driven Design

Related Related

  1. 1

    Where to put security when using DDD - domain driven design

  2. 2

    Where to put general purpose serialization class in domain driven design?

  3. 3

    Domain Driven Design: Can Infrastructure or Repositories use Domain objects?

  4. 4

    Domain Driven Design: Can Infrastructure or Repositories use Domain objects?

  5. 5

    Is there a mismatch between Domain-Driven Design repositories and Spring Data ones?

  6. 6

    Is there a mismatch between Domain-Driven Design repositories and Spring Data ones?

  7. 7

    Where is the call to persistence in the domain driven design

  8. 8

    Where to find Domain Driven Design consultants?

  9. 9

    When we shouldn't use Domain-Driven Design approach?

  10. 10

    Should Entities in Domain Driven Design and Entity Framework be the same?

  11. 11

    How much realistic should be a model in domain driven design?

  12. 12

    Layers in Domain Driven Design

  13. 13

    Where does the message bus service live in Domain Driven Design

  14. 14

    Meteor: Where should we put common functions?

  15. 15

    Where should we put the cast in following situation

  16. 16

    Domain Driven Design - Domain or Security

  17. 17

    Access Control in Domain Driven Design

  18. 18

    Domain Driven Design and batch processing

  19. 19

    Implementing Domain Driven Design Cost

  20. 20

    Implementing Domain Driven Design Cost

  21. 21

    Domain Driven Design Bounded Context Domain Objects

  22. 22

    Domain Driven Design: infrastructure concern or domain concern?

  23. 23

    Domain Driven Design: infrastructure concern or domain concern?

  24. 24

    Domain Driven Design. Entity type design

  25. 25

    Implementing Paging and Sorting with Domain Driven Design

  26. 26

    Implementing Domain-Driven Design and Transactions

  27. 27

    Domain driven design repository implementation in infrastructure layer

  28. 28

    Domain Driven Design in Node.js Application

  29. 29

    Fetching associated aggregates in Domain driven Design

HotTag

Archive