Owin Middleware for handling commands, typically used in CQRS applications. In this library, the philosophy is that commands are treated as resources in their own right and are PUT (i.e. PUT http://example.com/commands/c9e714c8-c9c1-433b-bcc6-de971b384a03
) to encourage idempotent handling.
- Simple way to wire up handlers for commands.
- Easy way to create handler pipelines.
- Strategies to support command versioning using Content-Type.
- An optional .NET client library to facilitate simple command invocation.
- Supports IETF HTTP Problem Details for errors (json only). Problem details are extendable and exceptions are re-raised when using .NET client.
- Simple to test without any environmental dependencies.
- Commands can be invoked embedded, in-mem and in-proc allowing the same pipeline to be invoked remote or locally.
- No dependencies!
public class MyCommand {}
public class MyCommandModule : CommandHandlerModule
{
public CommandModule()
{
For<MyCommand>()
.Handle(commandMessage => /* handle */);
}
}
public class Server
{
static void Main()
{
var resolver = new CommandHandlerResolver(new CommandModule());
var settings = new CommandHandlingSettings(resolver);
var middleware = CommandHandlingMiddleware.HandleCommands(settings);
Action<IAppBuilder> startup = (app) => app.Use(middleware);
using(WebApp.Start("http://localhost:8080", startup))
{
Console.WriteLine("Press any key to exit");
}
}
}
/* In client code */
using(var client = new HttpClient(){ BaseAddress = new Uri("http://localhost:8080") })
{
client.PutCommand(new MyCommand(), Guid.NewGuid());
}
See the examples for more advanced scenarios.