C# “完成”;“商业”;具有物理分离的事务多层体系结构
给定一个应用程序,如以下分层 应用层、业务层、数据层(通过WCF向业务公开,与应用/业务和数据物理分离)和数据。 如何完成从业务层开始但在数据层执行的事务 数据层:C# “完成”;“商业”;具有物理分离的事务多层体系结构,c#,wcf,transactions,n-tier-architecture,C#,Wcf,Transactions,N Tier Architecture,给定一个应用程序,如以下分层 应用层、业务层、数据层(通过WCF向业务公开,与应用/业务和数据物理分离)和数据。 如何完成从业务层开始但在数据层执行的事务 数据层: [DataContract] public class Customer { [DataMember] public int Id { get; set; } [DataMember] public string Name { get; set; } } [DataContract] public
[DataContract]
public class Customer
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
}
[DataContract]
public class Order
{
[DataMember]
public int Id { get; set; }
[DataMember]
public int CustomerId { get; set; }
}
/*
CRUD classes on both entities (I'm hoping this implementation does not matter on the data tier, as the transactions I hope to start on the business end and could potentially have different implementations on the data tier across different areas)
*/
业务:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Order
{
public int Id { get; set; }
public Customer PurchasedBy { get; set; }
}
public class PlaceOrderService
{
public void Execute(Order order)
{
try
{
// Begin Transaction
// Call to data tier to create/get customer depending on if they are new or existing
// Call to data tier to create order
// Commit transaction
}
catch (Exception)
{
// Rollback transactions
}
}
}
您需要通过服务设计和管理自己的逻辑事务 通常,这意味着以下流程:
我已经在基于消息传递的系统中看到了这一点,它运行得比较好,但确实需要一些开销来正确管理逻辑事务。如果数据层在物理上是分离的,并且不代表业务事务facsade,那么您必须运行自己的补偿资源管理器。如果数据层位于business facsade上,则可以创建SQL事务并将其传递到每个数据层调用中,以便它们可以加入事务
在许多情况下,我们拥有的唯一事务能力是SQL Server数据库引擎事务。在多数据库环境中,即使不能使用队列和其他非关系数据库,也无法使用它们。在这种情况下,您需要为交易的每个组成部分设计一个数据反转操作(即,如果您打算插入,则删除)在各种数据存储体系结构中,并使用这些体系结构来备份失败的事务。看看在这样的场景中,是否没有办法实现工作单元模式?我才刚刚开始研究它,所以第一次在多层环境中实现它让我在想从哪里开始时绊倒了。我实际上从未使用过它,但我相信这就是它的用途。它应该与WCF一起工作。