我下面有两个存储库类,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 .....
}
}