Basic implementation of CQRS pattern for .NET Core web APIs.
v1.0.0-rc2:
- Bypass controllers and execute Queries and Commands directly
- Supports simple (no params) and complex (with params) Queries and Commands
- Automatically parses params - Queries uses query string and Commands uses request body (json)
- Supports DI using default IServiceProvider
v1.0.0.-rc3:
- Fire & forget command handlers
- Get the lib package from nuget.org:
dotnet add package ASPNET.CQRS --version 1.0.0-rc2- Then you need to setup the
CQRSOptionsin yoursConfigureServicesmethod:
services.AddCQRS(options =>
{
options.BasePath = "/api";
options.Assemblies = new[] { Assembly.GetExecutingAssembly() };
});- After that, in yours Startup's
Configuremethod you need to configure CQRS's feature and CQRS's middleware:
app.UseCQRS();The example configuration above will load queries and commands from the same assembly as yours Startup class.
- Once you have done the configuration, you can add your first query:
[CQRSRoute("/ping")]
public class PingQuery : IQueryHandler
{
public Task Handle()
{
// noop
return Task.CompletedTask;
}
}- And then test it with your favourite tool to test web APIs, cor example with
cURL:
curl --request GET --url https://localhost:5001/api/ping