refactor: inject IRepository in PostgresProjector (DIP)#47
Merged
jorge07 merged 1 commit intojorge07:masterfrom Feb 22, 2026
Merged
refactor: inject IRepository in PostgresProjector (DIP)#47jorge07 merged 1 commit intojorge07:masterfrom
jorge07 merged 1 commit intojorge07:masterfrom
Conversation
D2.1 from Phase 2 roadmap. Violation: PostgresProjector injected the concrete PostgresRepository class instead of the IRepository interface, violating the Dependency Inversion Principle (Evans, Blue Book — interfaces in Domain, impls in Infrastructure; Martin, Clean Architecture ch.11). Consequence: The projector was untestable without a real database connection, and a compile-time dependency on a concrete infrastructure class crept into application wiring. Fix: - Add save(dto: ITransactionReadDTO): Promise<void> to IRepository (keeps TypeORM types out of the Domain interface) - PostgresRepository.save() now maps ITransactionReadDTO → Transactions entity internally; infrastructure detail stays in Infrastructure - PostgresProjector now depends only on IRepository and builds the DTO inline from the domain event - Remove dead Transactions.fromCreated() factory (no longer called) - Update InMemoryProjector test double to build DTO inline instead
jorge07
approved these changes
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PostgresProjectorinjected the concretePostgresRepositoryclass directly:Violation: Dependency Inversion Principle — upper layers should depend on abstractions, not concretions. The Domain already defines
IRepository; the projector bypassed it.Source: Evans (Blue Book) — "Interfaces in Domain, implementations in Infrastructure." Martin, Clean Architecture, ch. 11 (DIP).
Consequence: The projector is untestable without a real database. Any change to
PostgresRepository's internals could break the projector at a different layer boundary than intended.Fix
Add
save(dto: ITransactionReadDTO): Promise<void>toIRepository— uses only primitive types, keeps TypeORM out of the Domain interface.PostgresRepository.save()now mapsITransactionReadDTO → Transactionsentity internally. The infrastructure detail stays in Infrastructure.PostgresProjectornow depends only onIRepositoryand builds the DTO inline from the domain event fields.Remove dead
Transactions.fromCreated()— was only ever called from the projector; no longer needed.Update
InMemoryProjectortest double to build the DTO inline (removes its dependency on the deleted factory method).Tests
All 14 tests pass with no changes to test assertions.