qs.LibPack.UseCases
8.0.0
dotnet add package qs.LibPack.UseCases --version 8.0.0
NuGet\Install-Package qs.LibPack.UseCases -Version 8.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="qs.LibPack.UseCases" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="qs.LibPack.UseCases" Version="8.0.0" />
<PackageReference Include="qs.LibPack.UseCases" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add qs.LibPack.UseCases --version 8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: qs.LibPack.UseCases, 8.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package qs.LibPack.UseCases@8.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=qs.LibPack.UseCases&version=8.0.0
#tool nuget:?package=qs.LibPack.UseCases&version=8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
qsLibPack.UseCases
Biblioteca focada em abstrações para implementação de Use Cases seguindo princípios de Clean Architecture, com padrão semelhante ao MediatR (requests/handlers) e suporte a behaviors de pipeline (validação, exceção e unidade de trabalho).
Instalação
- Referencie o projeto
qsLibPack.UseCasesno seu solution. - Garanta que o projeto raiz chame o registro de DI.
Estrutura
Abstractions: Contratos principais (IRequest<T>,IUseCaseHandler<,>,IPipelineBehavior<,>,IUseCaseDispatcher,IResponse).Behaviors: Implementações de pipeline (ValidationBehavior,ExceptionHandlingBehavior,UnitOfWorkBehavior).Exceptions: Exceções customizadas (UseCaseException).Models: DTOs/VOs (Response,Response<T>).
Uso
- Crie uma requisição:
public sealed class CreateUserCommand : qsLibPack.UseCases.Abstractions.ICommand<qsLibPack.UseCases.Models.Response>
{
public string Name { get; init; } = string.Empty;
public string Email { get; init; } = string.Empty;
}
- Opcional: validador FluentValidation:
using FluentValidation;
public sealed class CreateUserValidator : AbstractValidator<CreateUserCommand>
{
public CreateUserValidator()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.Email).NotEmpty().EmailAddress();
}
}
- Handler:
using System.Threading;
using System.Threading.Tasks;
using qsLibPack.UseCases.Abstractions;
using qsLibPack.UseCases.Models;
public sealed class CreateUserHandler : IUseCaseHandler<CreateUserCommand, Response>
{
public Task<Response> Handle(CreateUserCommand request, CancellationToken cancellationToken)
=> Task.FromResult(Response.Ok());
}
- Registro de DI:
using Microsoft.Extensions.DependencyInjection;
using qsLibPack.UseCases.IoC;
var services = new ServiceCollection();
services.AddUseCases(typeof(CreateUserHandler).Assembly);
- Execução:
using System.Threading.Tasks;
using qsLibPack.UseCases;
using qsLibPack.UseCases.Abstractions;
var provider = services.BuildServiceProvider();
var dispatcher = provider.GetRequiredService<IUseCaseDispatcher>();
var response = await dispatcher.Send(new CreateUserCommand());
Behaviors
ValidationBehavior: executa validadoresIValidator<TRequest>. Em falha, lançaUseCaseExceptioncom erros.ExceptionHandlingBehavior: captura exceções não tratadas e converte paraUseCaseExceptioncom log.UnitOfWorkBehavior: aplicaIUnitOfWork.CommitAsyncapós handlers deICommand<TResponse>.
Versionamento Semântico
- O projeto segue versionamento semântico via campo
Versionno.csproj. Ajuste conforme mudanças.
Testes
- Consulte o projeto
qsLibPack.UseCases.Testpara exemplos de testes de unidade e integração dos behaviors.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- FluentValidation (>= 12.1.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- qs.LibPack (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 215 | 11/25/2025 |