https://github.com/andresantarosa/orchesflow
Orchestration lib to be used along MediatR + EntityFramework
https://github.com/andresantarosa/orchesflow
crqs mediatr nuget-package unitofwork
Last synced: 5 months ago
JSON representation
Orchestration lib to be used along MediatR + EntityFramework
- Host: GitHub
- URL: https://github.com/andresantarosa/orchesflow
- Owner: andresantarosa
- License: mit
- Created: 2021-11-25T22:26:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-25T20:00:28.000Z (over 3 years ago)
- Last Synced: 2025-10-05T08:34:18.445Z (9 months ago)
- Topics: crqs, mediatr, nuget-package, unitofwork
- Language: C#
- Homepage:
- Size: 46.9 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Orchesflow
This package provides some extra tools to be used along MediatR + EntityFramework focused to make working with events easier.
#### Ochestrator flow:

### Using Ochesflow
To enable Orchesflow just add it to your `ConfigureServices()` method at `Startup.cs`
````csharp
services.AddOrchesflow();
````
#### Sending a Command or Query
````csharp
using Orchesflow.Orchestration
public class MyController {
private readonly IOrchestrator _orchestrator;
public MyController(IOrchestrator orchestrator) {
_orchestrator = orchestrator
}
public async Task < IActionResult > ([FromBody] MyCommand command) {
// Use SendCommand to send a command
// A command triggers PreCommitEvents, Database commit and AfterCommitEvents
// For Queries the method SendQuery() should be used
// SendQuery() does not trigger events nor database commit
var response = await _orchestrator.SendCommand(command);
if (respose.Success)
return Ok(response.Data);
else
return BadRequest(response.Messages);
}
}
````
#### EventDispatcher
### EventDispatcher
The event dispatcher is the responsible to dispatch PreCommitEvents and AfterCommitEvents. This interface (`IEventDispatcher`) provides methods to add, remove, list or manualy event trigger (not recommended).
The event dispatcher is the responsible to dispatch PreCommitEvents and AfterCommitEvents. This interface (`IEventDispatcher`) provides methods to add, remove, list or manualy event trigger (not recommended).
##### Available methods for PreCommitEvents
##### Available methods
`GetPreCommitEvent(INotification evt)` => Returns a list with all PreCommitEvent
`GetPreCommitEvent(INotification evt)` => Returns a list with all PreCommitEvent
`AddPreCommitEvent(INotification evt)` => Adds new PreCommitEvent
`AddPreCommitEvent(INotification evt)` => Adds new PreCommitEvent
`RemovePreCommitEvent(INotification evt)` => Remove an existing PreCommitEvent
`RemovePreCommitEvent(INotification evt)` => Remove an existing PreCommitEvent
`FirePreCommitEvents(INotification evt)` => Manualy fire PreCommitEvent (not recommended)
`FirePreCommitEvents(INotification evt)` => Manualy fire PreCommitEvent (not recommended)
####
##### Available methods for PreCommitEvents
`GetAfterCommitEvent(INotification evt)` => Returns a list with all AfterCommitEvent
`GetAfterCommitEvent(INotification evt)` => Returns a list with all AfterCommitEvent
`AddAfterCommitEvent(INotification evt)` => Adds new AfterCommitEvent
`AddAfterCommitEvent(INotification evt)` => Adds new AfterCommitEvent
`RemoveAfterCommitEvent(INotification evt)` => Remove an existing AfterCommitEvent
`RemoveAfterCommitEvent(INotification evt)` => Remove an existing AfterCommitEvent
`FireAfterCommitEvents(INotification evt)` => Manualy fire AfterCommitEvent (not recommended)
The EventDispatcher functionality is only available when using `SendCommand()`
#### Commit
`SaveChanges()` method is called whenever MediatR CommandHandler finishes its job, unless any notification is found at the DomainNotifications container.
The Commit will only be evoked when using `SendCommand()`
#### PreCommitEvents
PreCommitEvents are MediatR events (`INotification`) that will be triggered before commit occurs. An unlimited number of PreCommitEvents can be added to EventDispatcher.
To add a PreCommitEvent use `IEventDispatcher.AddPreCommitEvents()`
#### AfterCommitEvents
AfterCommitEvents are MediatR events (`INotification`) that will be triggered after the commit occurs and if no notification is found at DomainNotifications container.. An unlimited number of PreCommitEvents can be added to EventDispatcher.
#### DomainNotifications container
This container intention is to store any errors that occurs during the request lifecycle and provide easy access to them from any part of your code. It is important to note that Commit action, AfterCommitEvents and the flow return depends if there is or there is not messages at DomainNotifications container. This funcionality should be used whenever you want to prevent the Commit to happen or prevent AfterCommitEvents to be triggered.
##### Available methods for IDomainNotifications interface
`AddNotification(string notification)` => Adds a new notification to container
`void CleanNotifications()` => Remove all notifications from container
### Fallbacks
Sometimes things just go wrong, in this case you can use fallbacks to go back and undo what you did.
To enable fallbacks, implement the interface `IFallbackable` at your RequestHandler or Notification Handler and put your logic inside `Fallback()` method.
There are three key moments for fallbacks.
- **An error occurred during a PreCommitEvent**: All PreCommitEvents already executed will have its fallback method called in the reverse order they were executed
- **An error occurred during Commit phase:** The calling handler will have its `Fallback` method triggered and also all PreCommitEvents executed will have its fallback method called in the reverse order they were executed
- **An error occurred during a AfterCommitEvent:** All PreCommitEvents already executed will have its `Fallback` method triggered, Handler fallback and PreCommitEvents fallbacks will also be triggered in the reverse worder they were executed.