Permalink
Browse files

Make replay functions clearer

  • Loading branch information...
thinkbeforecoding committed Jun 22, 2012
1 parent 38def97 commit 47780fc4c49b758fe45dd4621ab24d9116c8b3c6
Showing with 39 additions and 37 deletions.
  1. +35 −35 FsSimpleCQRS/CommandHandlers.fs
  2. +4 −2 FsSimpleCQRS/Domain.fs
@@ -1,35 +1,35 @@
-namespace SimpleCQRS
-open SimpleCQRS.Commands
-open SimpleCQRS.Events
-open InventoryItem
-
-
-type InventoryCommandHandlers (eventStore: IEventStore) =
- let load id = eventStore.GetEventsForAggregate id |> replayWith applyOnInventoryItem
- let save = eventStore.SaveEvents
-
- // load aggregate, execute f on it, then save
- let applyOn id version f =
- load id |>
- f |>
- save id version
-
- member x.Handle (c: CreateInventoryItem) =
- create c.InventoryItemId c.Name |>
- save c.InventoryItemId -1
-
- member x.Handle (c: DeactivateInventoryItem) =
- deactivate |>
- applyOn c.InventoryItemId c.OriginalVersion
-
- member x.Handle (c: RemoveItemsFromInventory) =
- remove c.Count |>
- applyOn c.InventoryItemId c.OriginalVersion
-
- member x.Handle (c: CheckInItemsToInventory) =
- checkIn c.Count |>
- applyOn c.InventoryItemId c.OriginalVersion
-
- member x.Handle (c: RenameInventoryItem) =
- rename c.NewName |>
- applyOn c.InventoryItemId c.OriginalVersion
+namespace SimpleCQRS
+open SimpleCQRS.Commands
+open SimpleCQRS.Events
+open InventoryItem
+
+
+type InventoryCommandHandlers (eventStore: IEventStore) =
+ let load id = eventStore.GetEventsForAggregate id |> replayInventoryItem
+ let save = eventStore.SaveEvents
+
+ // load aggregate, execute f on it, then save
+ let applyOn id version f =
+ load id |>
+ f |>
+ save id version
+
+ member x.Handle (c: CreateInventoryItem) =
+ create c.InventoryItemId c.Name |>
+ save c.InventoryItemId -1
+
+ member x.Handle (c: DeactivateInventoryItem) =
+ deactivate |>
+ applyOn c.InventoryItemId c.OriginalVersion
+
+ member x.Handle (c: RemoveItemsFromInventory) =
+ remove c.Count |>
+ applyOn c.InventoryItemId c.OriginalVersion
+
+ member x.Handle (c: CheckInItemsToInventory) =
+ checkIn c.Count |>
+ applyOn c.InventoryItemId c.OriginalVersion
+
+ member x.Handle (c: RenameInventoryItem) =
+ rename c.NewName |>
+ applyOn c.InventoryItemId c.OriginalVersion
View
@@ -38,6 +38,8 @@ module InventoryItem =
| :? InventoryItemDeactivated as e -> {s with Activated = false; }
| _ -> s
- let replayWith application =
+ let replay = Seq.fold
+
+ let replayInventoryItem events =
let empty = { Id = Guid.Empty; Activated = false}
- Seq.fold application empty
+ replay applyOnInventoryItem empty events

0 comments on commit 47780fc

Please sign in to comment.