Skip to content

How much is the domain and service layer really decoupled from infrastructure concerns? #356

Open
@shitikanth

Description

@shitikanth

The design of much of the domain and service layer implicitly depends on the dirty-checking and automatic flushing mechanism provided by the ORM. For example, in chapters 2-4, the repository doesn't even have a save method. The service method allocate modifies one of the batches and simply assumes that there is some mechanism that will keep track of changed batches and persist those changes at the end of the uow. This makes implementing a new repository/uow for a new persistence backend that would fulfill the same set of responsibilities much more non-trivial than would initially appear.

In particular, if you implement the SqlRepository given as an exercise at the end of chapter two and try to switch to that repository from the code in chapters 3-5, they will find that all the unit and e2e tests pass but the application is still broken! The service finds the correct batch to allocate the order line to, but that change is never persisted.

A few comments based on these observations:

  1. The passing of all unit and e2e tests and the application still being broken strongly suggests that we have made some implicit assumptions that we missed writing tests for.
  2. Since our business logic was still quite tightly coupled to the ORM anyways, was there actually much point to implementing the repository pattern after all?
  3. Considering that different repository implementations might have very different behaviors, is it even in principle possible to fix this problem? Since some repository implementations may have dirty-tracking behaviour and other not, the semantics of what happens if we modify an entity and don't save it will always be implementation-dependent, no?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions