OrigoDB domain events are an effort to support event driven, reactive designs. Capture domain events to trigger additional external behavior like sending emails, updating read models, sending messages, relaying through web sockets, etc. Zero or more events are produced during command execution. Events are not yet supported for remote connections or when using proxy.
Events are published via the Model.Events property, captured by the Engine during command execution and exposed through the Engine.CommandExecuted event.
Modeling domain events
Events should be immutable - you can’t change historical facts
Event names should be verbs in the past tense
Events must not expose mutable references to objects within the model
Events must implement the empty IEvent marker interface
Consider marking events Serializable
An example event
Publishing and subscribing to events
The Model.Events property is an object of type FilteringEventDispatcher with the following methods:
Subscribe and Send examples
Subscribe to events directly on the model or by handling Engine.CommandExecuted events:
Patterns for producing events
Any code with a reference to the model can publish events by calling Model.Events.Send(). The two obvious places are from within the model or within Command.Execute. Here are examples of both:
The FilteringEventDispatcher uses the subscribed handler and delegate objects as keys. To unsubscribe you must pass the same object used to subscribe. Subscriptions registered using the On cannot be unsubscribed.