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" />
                    
Directory.Packages.props
<PackageReference Include="qs.LibPack.UseCases" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=qs.LibPack.UseCases&version=8.0.0
                    
Install as a Cake Tool

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.UseCases no 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

  1. 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;
}
  1. Opcional: validador FluentValidation:
using FluentValidation;

public sealed class CreateUserValidator : AbstractValidator<CreateUserCommand>
{
    public CreateUserValidator()
    {
        RuleFor(x => x.Name).NotEmpty();
        RuleFor(x => x.Email).NotEmpty().EmailAddress();
    }
}
  1. 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());
}
  1. Registro de DI:
using Microsoft.Extensions.DependencyInjection;
using qsLibPack.UseCases.IoC;

var services = new ServiceCollection();
services.AddUseCases(typeof(CreateUserHandler).Assembly);
  1. 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 validadores IValidator<TRequest>. Em falha, lança UseCaseException com erros.
  • ExceptionHandlingBehavior: captura exceções não tratadas e converte para UseCaseException com log.
  • UnitOfWorkBehavior: aplica IUnitOfWork.CommitAsync após handlers de ICommand<TResponse>.

Versionamento Semântico

  • O projeto segue versionamento semântico via campo Version no .csproj. Ajuste conforme mudanças.

Testes

  • Consulte o projeto qsLibPack.UseCases.Test para exemplos de testes de unidade e integração dos behaviors.
Product 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.

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