【发布时间】:2014-10-19 19:03:56
【问题描述】:
给定一个应用程序分解为以下层/层
应用层、业务层、数据层(通过 WCF 向业务公开,与应用/业务和数据物理分离)和数据。 如何完成从业务层开始但作用于数据层的事务?
数据层:
[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
}
}
}
【问题讨论】:
-
在这样的场景中是否没有办法实现工作单元模式?我才刚刚开始研究它,所以第一次在多层环境中实施它让我不知道从哪里开始。
-
我实际上从未使用过它,但我相信这就是它的用途。它应该适用于 WCF。
标签: c# wcf transactions n-tier-architecture