|
1 |
| -namespace SimpleCQRS |
2 |
| -open SimpleCQRS.Commands |
3 |
| -open SimpleCQRS.Events |
4 |
| -open InventoryItem |
5 |
| - |
6 |
| - |
7 |
| -type InventoryCommandHandlers (eventStore: IEventStore) = |
8 |
| - let load id = eventStore.GetEventsForAggregate id |> replayWith applyOnInventoryItem |
9 |
| - let save = eventStore.SaveEvents |
10 |
| - |
11 |
| - // load aggregate, execute f on it, then save |
12 |
| - let applyOn id version f = |
13 |
| - load id |> |
14 |
| - f |> |
15 |
| - save id version |
16 |
| - |
17 |
| - member x.Handle (c: CreateInventoryItem) = |
18 |
| - create c.InventoryItemId c.Name |> |
19 |
| - save c.InventoryItemId -1 |
20 |
| - |
21 |
| - member x.Handle (c: DeactivateInventoryItem) = |
22 |
| - deactivate |> |
23 |
| - applyOn c.InventoryItemId c.OriginalVersion |
24 |
| - |
25 |
| - member x.Handle (c: RemoveItemsFromInventory) = |
26 |
| - remove c.Count |> |
27 |
| - applyOn c.InventoryItemId c.OriginalVersion |
28 |
| - |
29 |
| - member x.Handle (c: CheckInItemsToInventory) = |
30 |
| - checkIn c.Count |> |
31 |
| - applyOn c.InventoryItemId c.OriginalVersion |
32 |
| - |
33 |
| - member x.Handle (c: RenameInventoryItem) = |
34 |
| - rename c.NewName |> |
35 |
| - applyOn c.InventoryItemId c.OriginalVersion |
| 1 | +namespace SimpleCQRS |
| 2 | +open SimpleCQRS.Commands |
| 3 | +open SimpleCQRS.Events |
| 4 | +open InventoryItem |
| 5 | + |
| 6 | + |
| 7 | +type InventoryCommandHandlers (eventStore: IEventStore) = |
| 8 | + let load id = eventStore.GetEventsForAggregate id |> replayInventoryItem |
| 9 | + let save = eventStore.SaveEvents |
| 10 | + |
| 11 | + // load aggregate, execute f on it, then save |
| 12 | + let applyOn id version f = |
| 13 | + load id |> |
| 14 | + f |> |
| 15 | + save id version |
| 16 | + |
| 17 | + member x.Handle (c: CreateInventoryItem) = |
| 18 | + create c.InventoryItemId c.Name |> |
| 19 | + save c.InventoryItemId -1 |
| 20 | + |
| 21 | + member x.Handle (c: DeactivateInventoryItem) = |
| 22 | + deactivate |> |
| 23 | + applyOn c.InventoryItemId c.OriginalVersion |
| 24 | + |
| 25 | + member x.Handle (c: RemoveItemsFromInventory) = |
| 26 | + remove c.Count |> |
| 27 | + applyOn c.InventoryItemId c.OriginalVersion |
| 28 | + |
| 29 | + member x.Handle (c: CheckInItemsToInventory) = |
| 30 | + checkIn c.Count |> |
| 31 | + applyOn c.InventoryItemId c.OriginalVersion |
| 32 | + |
| 33 | + member x.Handle (c: RenameInventoryItem) = |
| 34 | + rename c.NewName |> |
| 35 | + applyOn c.InventoryItemId c.OriginalVersion |
0 commit comments