我正在爲存儲庫編寫T4模板。T4模板中的存儲庫
假設我們有客戶/訂單/產品表。然後我們有CustomerRepo,OrdersRepo和ProductsRepo。
對所有人都有一個通用的回購是一個好習慣嗎?
public partial class Repository
{
private IContext context;
public Repository()
{
_Product = new ProductRepo();
_Customer = new CustomerRepo();
}
public Repository(IContext context)
{
this.context = context;
_Product = new ProductRepo(context);
_Customer = new CustomerRepo(context);
}
private ProductRepo _Product;
public ProductRepo Product {
get { return _Product; }
}
// Product
private CustomerRepo _Customer;
public CustomerRepo Customer {
get { return _Customer; }
}
// Customer
}
僅供參考:它們都是DB中每個類的存儲庫。但我想製作一個通用的封裝它們,因此它們都有一個入口點,並允許更容易地訪問它們。 – 2010-06-28 07:57:11