HCQR 1.8.1
dotnet add package HCQR --version 1.8.1
NuGet\Install-Package HCQR -Version 1.8.1
<PackageReference Include="HCQR" Version="1.8.1" />
<PackageVersion Include="HCQR" Version="1.8.1" />
<PackageReference Include="HCQR" />
paket add HCQR --version 1.8.1
#r "nuget: HCQR, 1.8.1"
#:package HCQR@1.8.1
#addin nuget:?package=HCQR&version=1.8.1
#tool nuget:?package=HCQR&version=1.8.1
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 | Versions 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. |
-
net7.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.OpenApi (>= 1.6.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.