より大きなプロジェクトで使用するため、リポジトリとファクトリメソッドのパターンを一緒に理解するためのサンプル、アプリケーションを作成しています。
私が達成したいのは、Web サイトをさまざまな ORM ツールで動作させることができるようにすることです。
たとえば、Web サイトには LINQ to SQL および Ado エンティティ フレーム ワーク クラスが実装されており、ファクトリ メソッドを使用すると、これらの ORM の 1 つを「構成値を使用して」使用してリポジトリ オブジェクトにデータをロードします。
私が今まで得たものは次のようなものです
interface IRepository : IDisposable
{
IQueryable GetAll();
}
interface ICustomer : IRepository
{
}
public class CustomerLINQRepository : ICustomer
{
public IQueryable GetAll()
{
// get all implementation using linqToSql
}
public void Dispose()
{
throw;
}
public IRepository GetObject()
{
return this;
}
}
public class CustomerADORepository : ICustomer
{
public IQueryable GetAll()
{
// get all implementation using ADO
}
public void Dispose()
{
throw new NotImplementedException();
}
public IRepository GetObject()
{
return this;
}
}
// Filling a grid with data in a page
IRepository customers = GetCustomerObject();
this.GridView1.DataSource = customers.GetAll();
this.GridView1.DataBind();
////
public IRepository GetCustomerObject()
{
return new CustomerLINQRepository(); // this will return object based on a config value later
}
しかし、デザインの間違いがたくさんあると感じています。より良いデザインを得るために、それを理解するのを手伝ってくれることを願っています.