0

The scenario:

- infrastructure/
  ├── dtos/
  │   ├── note_dto
  │   ├── todo_dto
  │   └── note_preview_dto        <-- includes 3-5 previewTodos from database
  │                                   ***NotePreview needs this data***
  └── repositories/
      └── implementations

- domain/
  ├── entities/
  │   ├── note                    <-- Entity (Pure, no previewTodos)
  │   └── todo
  └── repositories/
      ├── note_repository         <-- abstract, doesn't know about previews
      └── todo_repository

- application/
  └── models/
      └── note_preview            <-- View-specific (not business rule - UI needs this)
                                      ***Needs previewTodos + Note***

- presentation/
  └── home/
      └── home_screen
          └── uses NotePreview
  1. The repository interface lives in domain/ and returns pure Note.
  2. The NotePreview lives in application/ and needs preview data (previewTodos).
  3. The NotePreviewDTO with previewTodos lives in infrastructure/.
  • Domain can’t depend on Application or Infrastructure.
  • Application needs previewTodos, but only Infrastructure sees them.

How can the application layer construct NotePreview using preview data from NotePreviewDto, if the repository interface (in domain) can't expose it, and the domain doesn't know anything about previews?

1 Answer 1

0

Your domain repositories are not there to provide 'views'. Domain repositories tend to have three interface method types:

  1. Methods required to retrieve Domain entities for the purpose of executing commands against those entities. e.g. GetById(int toDoId);

  2. Methods required to persist or remove Domain entities. e.g.: Add(ToDo toDo); Remove(ToDo toDo);

  3. Methods to support enforcing invariants when the knowledge to enforce that invariant requires more information than the current domain object is directly aware of. For example, to prevent duplicate names. e.g. IsNameAlreadyTaken(string name).

Your Domain repositories are not there to provide methods to retrieve 'Views'. For that your application layer can get a connection to your database via the infrastructure layer and query the database directly, skipping your domain layer altogether.

Trying to satisfy command handling and user interface view handling in your domain model will always stumble upon this type of issue. Keep your domain model focused on processing commands only and your design will magically fall into place much more easily.

Search CQRS for further guidance.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.