Hlibz.UseCases 1.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Hlibz.UseCases --version 1.0.0
                    
NuGet\Install-Package Hlibz.UseCases -Version 1.0.0
                    
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="Hlibz.UseCases" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hlibz.UseCases" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hlibz.UseCases" />
                    
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 Hlibz.UseCases --version 1.0.0
                    
#r "nuget: Hlibz.UseCases, 1.0.0"
                    
#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 Hlibz.UseCases@1.0.0
                    
#: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=Hlibz.UseCases&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hlibz.UseCases&version=1.0.0
                    
Install as a Cake Tool

Hlibz.UseCases icon

Hlibz.UseCases

Use cases for .NET apps with more than one client: HTTP endpoints, MCP tools, gRPC services and jobs all call the same handler, and every rule lives in the use case, validation included, written as DataAnnotations on the use case record.

dotnet add package Hlibz.UseCases
public sealed record CreateCityCommand(
    [Required, MaxLength(60)] string Name,
    [Range(1, 50_000_000)] int Population) : IUseCase;

public interface ICreateCityCommandHandler : IUseCaseHandler<CreateCityCommand, CityDto>;

internal sealed class CreateCityCommandHandler(AtlasDbContext db) : ICreateCityCommandHandler
{
    public async Task<Result<CityDto>> HandleAsync(CreateCityCommand useCase, CancellationToken cancellationToken = default)
    {
        ... // only valid use cases get here
    }
}

builder.Services.AddUseCases([typeof(CreateCityCommand).Assembly]);
builder.Services.AddUseCaseFilter<AuditFilter>(); // optional: runs for every use case

app.MapPost("cities", async (CreateCityCommand command, ICreateCityCommandHandler handler, CancellationToken ct) =>
    (await handler.HandleAsync(command, ct)).ToHttpResult());
  • A source generator lists the handlers at compile time (no assembly scan) and wraps each one in a pipeline: validation, your IUseCaseFilters, the handler. Clients inject the handler's own interface; there is no mediator.
  • Validation without ASP.NET Core that fails exactly as ASP.NET Core's AddValidation() does: record parameter attributes, nested objects and collection items (Costs[0].Value), IValidatableObject, async rules on .NET 11. An invalid use case returns Result.Invalid with ValidationErrors and never reaches the handler.
  • Rules that describe themselves: IDescribedRule and [RuleSummary] say what a custom rule checks, shaped like JSON Schema, for an OpenAPI document or a tool schema to publish.
  • A handler it can't register is a build error (HUC001-HUC007).

Targets .NET 10 and 11. Full documentation: github.com/hlib-zinchenko/Hlibz.UseCases.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Hlibz.UseCases:

Package Downloads
Hlibz.OpenApi.UseCases

Publishes Hlibz.UseCases in OpenAPI documents built with Microsoft.AspNetCore.OpenApi: the rules use cases describe (IDescribedRule, [RuleSummary]) as schema keywords and text, DataAnnotations on record constructor parameters, and the 400 of the operations whose use case can fail validation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.2 0 11/27/2026
2.0.0-preview.1 0 11/27/2026
1.0.0 92 11/25/2026
1.0.0-preview.2 60 11/23/2026
1.0.0-preview.1 79 11/22/2026