Repository
ドメイン駆動設計
アプリケーションがデータストアなど外部と接触するロジックと,接触しないロジックの境界に設置するinterface.
永続化も再構築もRepositoryを仲介する.
削除もRepositoryが提供する.
更新はRepositoryで行わない.
オブジェクト自身が更新して永続化を利用する.
code:IUserRepository.cs
interface IUserRepository {
void Save(User user);
User Find(UserId id);
User Find(UserName name);
void Delete(User user);
}
設計方針にはおもに2つの選択肢がある
集約の最新状態の永続化と再構築
コマンドとクエリの分離