Câu hỏi phỏng vấn DDD
Câu hỏi

What is the difference between Infrast...

Câu trả lời

In Domain-Driven Design (DDD), the concepts of Infrastructure Service and Repository serve distinct purposes and are used in different contexts within the architecture. Here is a detailed explanation of the differences between the two:

Repository

  1. Purpose:

    • A Repository is primarily concerned with the persistence of domain entities. It acts as an intermediary between the domain model and the data source, abstracting the details of data access and storage.
    • Repositories are used to encapsulate the logic required to access data sources, centralizing common data access functionality and providing better maintainability and decoupling the infrastructure or technology used to access databases from the domain[3][6].
  2. Location in Layers:

    • The interface for a Repository is typically defined in the Domain layer, while the implementation resides in the Infrastructure layer[1][6].
    • This separation ensures that the domain model remains agnostic of the underlying data access technology, adhering to the principle of dependency inversion[5][12].
  3. Functionality:

    • Repositories handle CRUD (Create, Read, Update, Delete) operations and are responsible for retrieving and persisting domain entities. They often work with aggregate roots to ensure transactional consistency within aggregates[3][6].
    • They do not contain business logic but focus on data access logic[9].

Infrastructure Service

  1. Purpose:

    • Infrastructure Services are concerned with the technical aspects and "plumbing" of the application, such as sending emails, logging, accessing external APIs, or handling file systems[1][7].
    • These services provide functionalities that are not specific to the domain but are necessary for the application's operation.
  2. Location in Layers:

    • Infrastructure Services are implemented in the Infrastructure layer. They are used by the Application layer or other services to perform tasks that are outside the core domain logic[1][7][12].
  3. Functionality:

    • Infrastructure Services handle operations that involve external systems or technical concerns. For example, an EmailService in the Infrastructure layer might be responsible for sending email notifications[1][7].
    • These services are often stateless and focus on providing reusable technical functionalities that support the application but do not encapsulate domain-specific rules or behaviors[7].

Key Differences

  • Scope and Focus:
    • Repositories are focused on data persistence and are tightly coupled with the domain model, ensuring that domain entities are correctly stored and retrieved.
    • Infrastructure Services are focused on technical operations and external system interactions, providing support functionalities that are not directly related to th...
senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What is the purpose of Service in Domain-Driven Design (DDD)

senior

What exactly are the Anti-Corruption layers in DDD? Provide an example.

senior

What is Context Mapping's purpose in DDD?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào