我有兩個存儲庫類, MoneyTransferRepository類被我的項目中的其他類使用。我是這樣設計的 - 是不是?如果不是,最好的方法是什麼?存儲庫模式問題
感謝
public interface IMoneyTransferRepository
{
void UpdateBalance();
}
public interface IOrderRepository
{
void Checkout();
void SaveOrder();
}
public class MoneyTransferRepository : IMoneyTransferRepository
{
DBDataContext DB;
public MoneyTransferRepository(IDbConnection connection)
{
DB = new DBDataContext(connection);
}
public void UpdateBalance()
{
//do something DB.Table1.Update
}
}
public class OrderRepository : IOrderRepository,IMoneyTransferRepository
{
DBDataContext DB;
IMoneyTransferRepository moneyTransferRepository;
public OrderRepository()
{
DB = new DBDataContext();
moneyTransferRepository = new MoneyTransferRepository(DB.Connection);
}
public void Checkout()
{
TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
try
{
UpdateBalance();
SaveOrder();
transactionScope.Complete();
}
catch
{
}
}
}
public void UpdateBalance()
{
moneyTransferRepository.UpdateBalance();
}
public void SaveOrder()
{
//do something DB.SaveOrder.Update ......
// DB.Updatestock .....
}
}