Repository
Entity返すやつ
P of EAA: Repository
Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.
アンチパターン
【コード問題集1】責務違反のRepository - little hands' lab
Repositoryの責務は集約単位でドメインオブジェクトと永続化層の変換を行うことであり、それ以外の処理を行うことは責務違反です。
やはりお前たちのRepositoryは間違っている - Qiita
Repositoryがビジネスロジックを持ってしまう
ビジネスロジックに反したことができてしまう(適切に隠蔽されない)
自由に更新できるリポジトリは作ってはいけない
かわりに、リポジトリを介して(DDDの)集約を利用し、集約のメソッドを使って制約条件が壊れないようにする
アプリ固有の複雑なクエリを投げてしまう
CQSを使う
Commandはリポジトリを使うが、Queryの際はリポジトリを使わず、Serviceからクエリを発行する
Repositoryの複雑化は防がれる #単一責任原則