この1週間ほど、リポジトリパターンに関する多くの記事やチュートリアルを読んでいます。多くの記事は、リポジトリパターンを作業単位パターンに密接に結び付けています。これらの記事では、通常、次のようなコードを見つけます。
interface IUnitOfWork<TEntity>
{
void RegisterNew(TEntity entity);
void RegisterDirty(TEntity entity);
void RegisterDeleted(TEntity entity);
void Commit();
void Rollback();
}
interface IRepository<TKey, TEntity>
{
TEntity FindById(TKey id);
IEnumerable<TEntity> FindAll();
void Add(TEntity entity);
void Update(TEntity entity);
void Delete(TEntity entity);
}
class Repository : IRepository<int, string>
{
public Repository(IUnitOfWork<string> context)
{
this.context = context;
}
private IUnitOfWork<string> context;
public void Add(string entity)
{
context.RegisterNew(entity);
}
public void Update(string entity)
{
context.RegisterDirty(entity);
}
public void Delete(string entity)
{
context.RegisterDeleted(entity);
}
/* Entity retrieval methods */
}
作業単位オブジェクトは、基になるデータストア(私の場合はLDAP経由で通信するディレクトリサービス)内のオブジェクトの追加、更新、または削除を処理することを目的としていることを正しく理解していますか?それが本当なら、それはオブジェクトの検索も処理するべきではありませんか?なぜそれは提案されたUoWインターフェースの一部ではないのですか?