Repository navigation
1.0.0-preview.1
Pre-releaseFirst preview 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.
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 on record constructor parameters;
- nested objects and collection items, with keys such as
Costs[0].Value; IValidatableObject, which runs only once every property rule has passed;- on .NET 11, async rules (
AsyncValidationAttribute,IAsyncValidatableObject).
A failure returns
Result.Invalidby default. UseUseCaseValidationOptionsto choose another status, change the message, set the depth limit or turn validation off. -
IUseCaseFilter: open pipeline steps, registered withAddUseCaseFilter<T>(), that run in order for every use case. A filter's failure becomes the handler'sResult<T>. -
Rules describe themselves, without depending on OpenAPI:
IDescribedRuleon a customValidationAttributefills a JSON Schema shapedRuleDescription;[RuleSummary]explains in plain text a rule that has no attribute of its own.
OpenAPI and MCP adapters can publish both.
-
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.
This is a preview, so the API may change before 1.0.0.
https://www.nuget.org/packages/Hlibz.UseCases/1.0.0-preview.1