First steps
Last updated
Last updated
OpenSleigh is intended to be flexible and developer-friendly. It makes use of Dependency Injection for its own initialization and the setup of the dependencies.
The first step, once you have installed the , is to add OpenSleigh to the Services collection:
OpenSleigh needs to be configured to point to a specific Transport bus and a Persistence mechanism for the Saga States:
In this example, the system is configured to use RabbitMQ as message bus and MongoDB to persist the data.
IMPORTANT: for detailed instructions on each Transport and Persistence mechanism, please refer to the library's documentation.
Dependency injection can be used to provide services to a Saga.
Now, all you have to do is register and configure the Saga:
Sagas can also hold some state. In this case, we need to define its shape by creating a class
or a record
and setting it on the Saga:
Now you can register it this way:
IMPORTANT: each Saga should have its own State class. Don't reuse State classes!
A Saga is a simple class inheriting from the base class:
The State can be accessed later on via this.Context.State
and is also persisted automatically after a message is processed. For more details, check the page.