Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.62 KB

README.md

File metadata and controls

65 lines (46 loc) · 1.62 KB

ASPNET.CQRS

Build RC NuGet Badge

Basic implementation of CQRS pattern for .NET Core web APIs.

Features

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

How to use?

  1. Get the lib package from nuget.org:
dotnet add package ASPNET.CQRS --version 1.0.0-rc2
  1. Then you need to setup the CQRSOptions in yours ConfigureServices method:
services.AddCQRS(options =>
{
    options.BasePath = "/api";
    options.Assemblies = new[] { Assembly.GetExecutingAssembly() };
});
  1. After that, in yours Startup's Configure method 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.

  1. 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;
    }
}
  1. 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