我是CQRS& DDD和我正在使用MS WideWorldImporters数据库的练习,目前我坚持购买订单放置命令,说实话我不知道它应该是什么样子,你能指导我吗? 我应该有1个PlaceOrderCommand和处理程序应该使用它来创建PurchaseOrder填充其OrderLines而不是保存。如果是,那么当域模型看起来如何时Command应该是这样的:
示例域模型:
public class PurchaseOrdersCommandHandler :
ICommandHandler<PlacePurchaseOrder>
{
private readonly IPurchaseOrderRepository purchaseOrderRepository;
public PurchaseOrdersCommandHandler(IPurchaseOrderRepository purchaseOrderRepository)
{
this.purchaseOrderRepository = purchaseOrderRepository;
}
public void Handle(PlacePurchaseOrder command)
{
// TODO: based on command Create Purchase order with its line items and save it to db as a whole
}
}
示例命令处理程序:
$hostName = "https://server.visualstudio.com/WebAndMobile/:8080"
$user = "user"
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($user,$password)
$server=Get-TfsServer -Name $hostName -credential $credential -all
答案 0 :(得分:1)
你能不能做这样的事情吗?
public void Handle(PlacePurchaseOrder command)
{
var purchaseOrder = PurchaseOrder.CreatePurchaseOrder(command.id, command.upplierID, command.orderDate, command.deliveryMethodID, command.contactPersonID);
foreach(int stockItemID in command.OrderLines)
{
purchaseOrder.AddPurchaseOrderLine(stockItemID)
}
this.purchaseOrderRepository.Save(purchaseOrder);
}