Repository navigation
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>(returnsResult),IUseCaseHandler<TUseCase, TResult>(returnsResult<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 returnsResult.Invalidby default;UseCaseValidationOptionschanges the status, message, depth limit, or turns validation off. UseCaseValidationOptions.DisplayNamePolicynames a property without a[Display]name in validation messages, e.g.JsonNamingPolicy.SnakeCaseLower. Off by default.IUseCaseFilter: open pipeline steps, registered withAddUseCaseFilter<T>(), that run in order for every use case.- Rules describe themselves without depending on OpenAPI:
IDescribedRuleand[RuleSummary]. Hlibz.OpenApi.UseCases publishes them in OpenAPI documents. IUseCaseCataloglists 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.