如何在工作流基礎中實現簡單的業務工作流?

[英]How to implement simple business workflow in Workflow Foundation?


I've started to look through WF and can't catch how it can replace my Domain object functionality. Here is simple Domain object scenario:

我已經開始研究WF了,但是我不知道它是如何替代我的域對象功能的。以下是簡單的域對象場景:

class Order {
    public int Id {get;}

    public OrderStatus Status {get;private set;}

    public void Approve () {
       if (Status >= OrderStatus.Approved)
          throw new InvalidOperationException("It is impossible to approve as order
          Status:" + Status);

       privateMethodCall();
       Status = Status.Approved;
    }

    public void Complete () {
       if (Status >= OrderStatus.Completed)
          throw new InvalidOperationException("It is impossible to Complete as order
          Status:" + Status);

       privateMethodCall1();
       Status = Status.Completed;
    }
}

I've read that WF can do it better as Approve and Complete code will be placed in one place and it won't be possible to call them in wrong order. Is it true? and if it is true can you show me how it will look in WF using object model (not xaml).

我已經讀到過,WF可以做得更好,因為批准和完整的代碼將放在一個地方,並且不可能以錯誤的順序調用它們。是真的嗎?如果這是真的,你能告訴我它在WF中如何使用對象模型(而不是xaml)嗎?

Thanks in advance.

提前謝謝。

1 个解决方案

#1


1  

There are 2 ways that you can use workflow:

有兩種方法可以使用工作流:

  • As a sequential process, in this case your sytem will move through the steps defined in the process and therefore things will not be called out of order.
  • 作為一個連續的過程,在這種情況下,您的系統將通過流程中定義的步驟,因此不會出現無序調用的情況。
  • As a state machine, this would keep track of which state your order is in and what transitions are allowed. This is the one that most closely matches your code, see: http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx
  • 作為狀態機,這將跟蹤您的訂單處於哪個狀態以及允許哪些轉換。這是與您的代碼最匹配的一個,參見:http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx。

But, if you allready have code that works, I would not change it, you just add an extra layer of complexity without getting any business value.

但是,如果您已經有了能夠工作的代碼,我不會更改它,您只需要添加額外的復雜性層,而不會獲得任何業務價值。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/02/22/72f24fa3eabeb6c63f23f8cd3db212f1.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com