HCQR 1.8.1

dotnet add package HCQR --version 1.8.1
                    
NuGet\Install-Package HCQR -Version 1.8.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HCQR" Version="1.8.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HCQR" Version="1.8.1" />
                    
Directory.Packages.props
<PackageReference Include="HCQR" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HCQR --version 1.8.1
                    
#r "nuget: HCQR, 1.8.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HCQR@1.8.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HCQR&version=1.8.1
                    
Install as a Cake Addin
#tool nuget:?package=HCQR&version=1.8.1
                    
Install as a Cake Tool

HCQR

The HCQR package provides a lightweight HCQR (Holistic Command Query Responsibility) middleware for ASP.NET Core applications, making it easy to map routes directly to handlers that implement the IHandler interface. This ensures a more clean and direct flow from request to response without any excess boilerplate.

Heavily inspired by CQRS, but more holistic in its approch and condences the handle, response and request objects.

Features

  • Directly maps HTTP routes to command or query handlers.
  • Handles both query parameters and request bodies.
  • Automatically registers and resolves handler types.
  • Allows for custom route patterns with placeholders.

Getting Started

1. Installation

Install the HCQR package from NuGet:

dotnet add package HCQR

2. Configuration

In your Startup.cs or wherever you configure your services and middleware, do the following:

public void ConfigureServices(IServiceCollection services)
{
    services.AddHCQR();
    // ... other services
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseHCQR();
    // ... other middlewares
}

3. Creating Handlers

To create a handler, implement the IHandler interface:

[Get("/api/user/{id}")]
public class GetUserHandler : IHandler
{
    public IResponse Handle(IRequest request)
    {
        // Handle the request and return the response
    }
}

Make sure to mark the handler with the [Get] or [Post] attribute to specify the route.

4. Creating Requests & Responses

Each handler should have a nested class that implements IRequest. For example:

[Get("/api/user/{id}")]
public class GetUserHandler : IHandler
{
    public class Request : IRequest
    {
        public int Id { get; set; }
    }

    public IResponse Handle(IRequest request)
    {
        var req = (Request)request;
        // Handle the request using req.Id and return the response
    }
}

Responses can be any object implementing the IResponse interface.

5. Handling Routes

Once everything is set up, any incoming request that matches the mapped routes will be automatically directed to the corresponding handler. The HCQRMiddleware will deserialize any parameters in the route, query string, or body and pass them to your handler.

Contribute

Your contributions to improve HCQR are welcome! Feel free to open issues or submit pull requests. License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.1 176 9/28/2023
1.7.1 176 9/25/2023
1.6.1 168 9/24/2023
1.5.1 171 9/23/2023
1.4.1 159 9/23/2023
1.0.0 174 9/23/2023