Skip to content

Releases

2.0.0-preview.2

2.0.0-preview.2 Pre-release
Pre-release

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 27 Nov 13:25

Changes

  • Built on Hlibz.Results 3.0.0-preview.2, which adds the ambient errors ConcurrencyConflict and RateLimited. A use case filter can return them for any handler, also after calling next: a transaction filter can answer a save whose rows changed meanwhile with ConcurrencyConflict. The IUseCaseFilter docs 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

2.0.0-preview.1 Pre-release
Pre-release

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 27 Nov 10:01

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.FailureStatus and FailureMessage are gone: the error carries its own status, and the HTTP layer picks 400 or 422.
  • A filter's own failure must be an ambient error (Forbidden, Unauthorized or Unavailable) 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> returns Result<TResult, TError>, where TError is a union of 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.ErrorSetType names a use case's error set, so IUseCaseCatalog tells 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

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 25 Nov 08:46

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

1.0.0-preview.2

1.0.0-preview.2 Pre-release
Pre-release

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 23 Nov 14:07

No breaking changes.

Features

  • UseCaseValidationOptions.DisplayNamePolicy: a JsonNamingPolicy that names a property without a [Display] name in validation messages, e.g. JsonNamingPolicy.SnakeCaseLower for "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

1.0.0-preview.1 Pre-release
Pre-release

Choose a tag to compare

@hlib-zinchenko hlib-zinchenko released this 22 Nov 17:20

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> (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 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.Invalid by default. Use UseCaseValidationOptions to choose another status, change the message, set the depth limit or turn validation off.

  • IUseCaseFilter: open pipeline steps, registered with AddUseCaseFilter<T>(), that run in order for every use case. A filter's failure becomes the handler's Result<T>.

  • Rules describe themselves, without depending on OpenAPI:

    • IDescribedRule on a custom ValidationAttribute fills a JSON Schema shaped RuleDescription;
    • [RuleSummary] explains in plain text a rule that has no attribute of its own.

    OpenAPI and MCP adapters can publish both.

  • 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.

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