Skip to content

1.0.0

Latest

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 25 Nov 08:46
· 5 commits to main since this release

The first stable release of Hlibz.UseCases: use cases that every client of an app (HTTP endpoints, MCP tools, gRPC services, jobs) calls the same way, with their validation written as DataAnnotations on the use case record. No ASP.NET Core dependency.

The code is the same as 1.0.0-preview.2. No breaking changes since the previews.

Features

  • Contracts: IUseCase, IUseCaseHandler<TUseCase> (returns Result), IUseCaseHandler<TUseCase, TResult> (returns Result<TResult>), on Hlibz.Results 2.2.0.
  • A source generator, packed in the package, finds every handler at compile time. No assembly scan. AddUseCases(assemblies) registers each handler under its own interface, wrapped in a generated pipeline: validation, then your filters, then the handler. There's no mediator: clients inject the handler's interface.
  • Validation follows the same rules as ASP.NET Core's AddValidation(), checked by parity tests against Microsoft.Extensions.Validation: attributes on properties and record constructor parameters, nested objects and collection items, IValidatableObject, and on .NET 11 async rules. A failure returns Result.Invalid by default; UseCaseValidationOptions changes the status, message, depth limit, or turns validation off.
  • UseCaseValidationOptions.DisplayNamePolicy names a property without a [Display] name in validation messages, e.g. JsonNamingPolicy.SnakeCaseLower. Off by default.
  • IUseCaseFilter: open pipeline steps, registered with AddUseCaseFilter<T>(), that run in order for every use case.
  • Rules describe themselves without depending on OpenAPI: IDescribedRule and [RuleSummary]. Hlibz.OpenApi.UseCases publishes them in OpenAPI documents.
  • IUseCaseCatalog lists every use case, its handler and result type, and whether it can fail validation.
  • Build errors HUC001–HUC007 report handlers the pipeline can't wrap.
  • Targets net10.0 and net11.0.

https://www.nuget.org/packages/Hlibz.UseCases/1.0.0