|
| 1 | +# Mando |
| 2 | +A super lightweight and free alternative to libraries that provide |
| 3 | +decoupled, in-process communication. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +[](https://github.com/henningtandberg/Mando/actions/workflows/build-test.yml) |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Usage |
| 16 | +You can use the package directly or fork this repo and create your own, |
| 17 | +custom implementation. |
| 18 | + |
| 19 | +## Installation |
| 20 | +The easiest way to add Mando to your project via [NuGet](https://www.nuget.org/packages/Mando). |
| 21 | + |
| 22 | +## Features |
| 23 | +The features of this library are limited by design, so that the library will |
| 24 | +be easier to extend if you decide to fork the repo and create a more custom |
| 25 | +implementation. The core features are, and will always be: |
| 26 | + |
| 27 | +### Single command, single handler. |
| 28 | +```csharp |
| 29 | +internal sealed MyCustomCommand : ICommand; |
| 30 | + |
| 31 | +internal sealed MyCustomCommandHandler : ICommandHandler<MyCustomCommand> |
| 32 | +{ |
| 33 | + public Task Execute(MyCustomCommand command) |
| 34 | + { |
| 35 | + // Your magic here! |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Single command, multiple handlers. |
| 41 | +```csharp |
| 42 | +internal sealed MyCustomCommand : ICommand; |
| 43 | + |
| 44 | +internal sealed MyCustomCommandHandlerOne : ICommandHandler<MyCustomCommand> |
| 45 | +{ |
| 46 | + public Task Execute(MyCustomCommand command) |
| 47 | + { |
| 48 | + // Your magic here! |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +internal sealed MyCustomCommandHandlerTwo : ICommandHandler<MyCustomCommand> |
| 53 | +{ |
| 54 | + public Task Execute(MyCustomCommand command) |
| 55 | + { |
| 56 | + // And some other magic here! |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### Multiple commands, single handler |
| 62 | + |
| 63 | +```csharp |
| 64 | +internal sealed MyCustomCommandOne : ICommand; |
| 65 | +internal sealed MyCustomCommandTwo : ICommand; |
| 66 | + |
| 67 | +internal sealed MyCustomCommandHandler : |
| 68 | + ICommandHandler<MyCustomCommandOne>, ICommandHandler<MyCustomCommandTwo> |
| 69 | +{ |
| 70 | + public Task Execute(MyCustomCommandOne command) |
| 71 | + { |
| 72 | + // Your magic here! |
| 73 | + } |
| 74 | + |
| 75 | + public Task Execute(MyCustomCommandTwo command) |
| 76 | + { |
| 77 | + // Even more magic here! |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +### Dependency Injection |
| 83 | +```csharp |
| 84 | +services.AddMando(Assembly.GetExecutingAssembly())) |
| 85 | +``` |
| 86 | + |
| 87 | +This registers |
| 88 | +- `ICommandHandler<TCommand>` : All implementations are registered as Scoped |
| 89 | +- `IDispatcher` as Scoped |
| 90 | + |
| 91 | +### Usage |
| 92 | +```csharp |
| 93 | +internal sealed class Application(IDispatcher dispatcher) : IApplication |
| 94 | +{ |
| 95 | + public Task RunAsync() => dispatcher.Dispatch(new DoSomethingCommand()); |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +Checkout [Mando.Example](https://github.com/henningtandberg/Mando/tree/main/Mando/Mando.Example) for a working example. |
0 commit comments