Repository navigation
Releases
2.0.0-preview.2
Changes
- Built on Hlibz.Results 3.0.0-preview.2, which adds the ambient errors
ConcurrencyConflictandRateLimited. A use case filter can return them for any handler, also after callingnext: a transaction filter can answer a save whose rows changed meanwhile withConcurrencyConflict. TheIUseCaseFilterdocs and the pipeline's message for an undeclared filter error now name them.
This is a preview: the API may still change before 2.0.0.
https://www.nuget.org/packages/Hlibz.UseCases/2.0.0-preview.2
2.0.0-preview.1
Breaking changes
- .NET 11 only, on Hlibz.Results 3.0. .NET 10 apps stay on 1.x.
- An invalid use case fails with the ambient
ValidationFailed.UseCaseValidationOptions.FailureStatusandFailureMessageare gone: the error carries its own status, and the HTTP layer picks400or422. - A filter's own failure must be an ambient error (
Forbidden,UnauthorizedorUnavailable) when the handler declares its errors. Any other error from a filter throws for such a handler.
Features
-
Handlers declare their errors.
IUseCaseHandler<TUseCase, TResult, TError>returnsResult<TResult, TError>, whereTErroris aunionof error types. Clients switch over the errors exhaustively, and documentation lists each one with its data.public union DeleteCityError(CityNotFound, CityInUse); public interface IDeleteCityCommandHandler : IUseCaseHandler<DeleteCityCommand, Unit, DeleteCityError>;
-
UseCaseDescriptor.ErrorSetTypenames a use case's error set, soIUseCaseCatalogtells adapters which errors each use case fails with. Hlibz.OpenApi.UseCases uses it for OpenAPI documents; an app can use it for MCP tools. -
The samples are plain minimal API endpoints on Hlibz.Results.AspNetCore only.
This is a preview: the API may still change before 2.0.0.
https://www.nuget.org/packages/Hlibz.UseCases/2.0.0-preview.1
1.0.0
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.
1.0.0-preview.2
No breaking changes.
Features
UseCaseValidationOptions.DisplayNamePolicy: aJsonNamingPolicythat names a property without a[Display]name in validation messages, e.g.JsonNamingPolicy.SnakeCaseLowerfor "The first_name field is required.". Error keys stay property paths. Off by default, which keeps parity with Microsoft.Extensions.Validation.
Other
- The Atlas samples use the published Hlibz.OpenApi.UseCases.
- The package icon renders without white edges.
https://www.nuget.org/packages/Hlibz.UseCases/1.0.0-preview.2
1.0.0-preview.1
First 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