cportetdev.ZeroCqrs 0.0.7

dotnet add package cportetdev.ZeroCqrs --version 0.0.7
                    
NuGet\Install-Package cportetdev.ZeroCqrs -Version 0.0.7
                    
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="cportetdev.ZeroCqrs" Version="0.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="cportetdev.ZeroCqrs" Version="0.0.7" />
                    
Directory.Packages.props
<PackageReference Include="cportetdev.ZeroCqrs" />
                    
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 cportetdev.ZeroCqrs --version 0.0.7
                    
#r "nuget: cportetdev.ZeroCqrs, 0.0.7"
                    
#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 cportetdev.ZeroCqrs@0.0.7
                    
#: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=cportetdev.ZeroCqrs&version=0.0.7
                    
Install as a Cake Addin
#tool nuget:?package=cportetdev.ZeroCqrs&version=0.0.7
                    
Install as a Cake Tool

ZeroCqrs — Le CQRS léger

Zéro dépendance - Ask / Execute - Rien de plus

Installation

Ajouter le package (Pas encore disponible sur NuGet, utiliser le projet localement)

dotnet add package ZeroCqrs

Déclarer le service (dans Program.cs ou Startup.cs)

// Tout en un
builder.Services.AddZeroCqrs();

// Ou séparé (pour un contrôle plus fin)
builder.Services.AddZeroCqrsQueries(typeof(Program));
builder.Services.AddZeroCqrsCommands(typeof(Program));

Requête (Query<T,R>) - Je récupère des données

Cas d'usage : Demander une requête et obtenir un résultat.

Exemple d'implémentation du Handler

// Récupération d’un utilisateur par son ID
public record GetUserQuery(int Id) : IZeroQuery<UserDto>;

public class GetUserQueryHandler(AppDbContext db) : IZeroQueryHandler<GetUserQuery, UserDto>
{
    public async Task<UserDto> Answer(GetUserQuery query, CancellationToken ct = default)
    {
        return await db.Users
            .Where(u => u.Id == query.Id)
            .Select(u => new UserDto(u.Name, u.Email))
            .FirstAsync(ct);
    }
}

Exemple d’utilisation

public class ServiceUtilisateur(IZeroQueryBus queryBus)
{
    public async Task RecupererUtilisateur()
    {
        int userId = 42;
        var query = new GetUserQuery(userId);

        var user = await queryBus.Ask(query);

        Console.WriteLine($"Utilisateur : {user.Name}, Email : {user.Email}");
    }
}

Commande (Command<T>) - J’exécute une action

Cas d'usage : Exécuter une commande sans résultat attendu.

Exemple d'implémentation du Handler

// Suppression d’un utilisateur
public record DeleteUserCommand(int Id) : IZeroCommand;

public class DeleteUserCommandHandler(AppDbContext db) : IZeroCommandHandler<DeleteUserCommand>
{
    public async Task Execute(DeleteUserCommand command, CancellationToken ct = default)
    {
        var user = await db.Users.FindAsync(new object[] { command.Id }, ct);
        if (user != null)
        {
            db.Users.Remove(user);
            await db.SaveChangesAsync(ct);
        }
    }
}

Exemple d’utilisation

public class ServiceUtilisateur(IZeroCommandBus commandBus)
{
    public async Task SupprimerUtilisateur()
    {
        int userId = 42;
        var command = new DeleteUserCommand(userId);

        await commandBus.Execute(command);
    }
}

Commande avec résultat (Command<T,R>) - J’exécute une action et je reçois un résultat

Cas d'usage : Exécuter une commande et obtenir un résultat.

Exemple d'implémentation du Handler

// On créé un utilisateur et on retourne son ID

public record CreateUserCommand(string Name, string Email) : IZeroCommand<int>;

public class CreateUserCommandHandler(AppDbContext db) : IZeroCommandHandler<CreateUserCommand, int>
{
    public async Task<int> Execute(CreateUserCommand command, CancellationToken ct = default)
    {
        var user = new User { Name = command.Name, Email = command.Email };
        db.Users.Add(user);
        await db.SaveChangesAsync(ct);
        return user.Id; // l’ID créé
    }
}

Exemple d’utilisation

public class ServiceUtilisateur(IZeroCommandBus commandBus)
{
    public async Task CreerUtilisateur()
    {
        string nom = "Alice";
        string email = "alice@example.com";

        var command = new CreateUserCommand(nom, email);

        int newId = await commandBus.Execute(command);

        Console.WriteLine($"Nouvel utilisateur créé avec l'ID : {newId}");
    }
}
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 is compatible.  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 is compatible.  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
0.0.7 469 12/11/2025