SeaQRS 1.2.1

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

SeaQRS

A lightweight CQRS library for .NET that provides strongly-typed commands and queries with delegate-based dependency injection.

Installation

dotnet add package SeaQRS

Concepts

SeaQRS has two building blocks:

Type Input Output Use for
CommandBase<TRequest> TRequest none operations that change state
CommandBase<TRequest, TResponse> TRequest TResponse state changes that return a result
QueryBase<TRequest, TResponse> TRequest TResponse reads with a parameter
QueryBase<TResponse> none TResponse parameterless reads

Usage

Command

public record DeleteUserRequest(Guid UserId);

public class DeleteUserCommand : CommandBase<DeleteUserRequest>
{
    private readonly IUserRepository _users;

    public DeleteUserCommand(IUserRepository users)
    {
        _users = users;
    }

    public override async Task Run(DeleteUserRequest request)
    {
        await _users.DeleteAsync(request.UserId);
    }
}

Command with a response

Use this when the caller needs something back from the operation, such as a generated identifier.

public record CreateUserRequest(string Name);

public class CreateUserCommand : CommandBase<CreateUserRequest, Guid>
{
    private readonly IUserRepository _users;

    public CreateUserCommand(IUserRepository users)
    {
        _users = users;
    }

    public override async Task<Guid> Run(CreateUserRequest request)
    {
        return await _users.CreateAsync(request.Name);
    }
}

Query

public record GetUserRequest(Guid UserId);
public record UserDto(Guid Id, string Name);

public class GetUserQuery : QueryBase<GetUserRequest, UserDto>
{
    private readonly IUserRepository _users;

    public GetUserQuery(IUserRepository users)
    {
        _users = users;
    }

    public override async Task<UserDto> Run(GetUserRequest request)
    {
        return await _users.GetAsync(request.UserId);
    }
}

Registration

Register your handlers in Program.cs using the extension methods on IServiceCollection. You control the lifetime of each handler individually.

services.AddCommandScoped<DeleteUserCommand, DeleteUserRequest>();
services.AddCommandScoped<CreateUserCommand, CreateUserRequest, Guid>();
services.AddQueryScoped<GetUserQuery, GetUserRequest, UserDto>();

Each type has Transient, Scoped, and Singleton convenience methods, plus a lifetime overload if you need something dynamic:

services.AddCommand<DeleteUserCommand, DeleteUserRequest>(ServiceLifetime.Scoped);
services.AddCommand<CreateUserCommand, CreateUserRequest, Guid>(ServiceLifetime.Scoped);
services.AddQuery<GetUserQuery, GetUserRequest, UserDto>(ServiceLifetime.Scoped);

Injection

Handlers are registered and injected by their interface, keeping your consumers decoupled from the handler implementations.

public class UsersController : ControllerBase
{
    private readonly IQuery<GetUserRequest, UserDto> _getUser;
    private readonly ICommand<DeleteUserRequest> _deleteUser;
    private readonly ICommand<CreateUserRequest, Guid> _createUser;

    public UsersController(
        IQuery<GetUserRequest, UserDto> getUser,
        ICommand<DeleteUserRequest> deleteUser,
        ICommand<CreateUserRequest, Guid> createUser)
    {
        _getUser = getUser;
        _deleteUser = deleteUser;
        _createUser = createUser;
    }

    [HttpGet("{id}")]
    public async Task<IActionResult> Get(Guid id)
    {
        var result = await _getUser.Run(new GetUserRequest(id));
        return Ok(result);
    }

    [HttpPost]
    public async Task<IActionResult> Create(string name)
    {
        var id = await _createUser.Run(new CreateUserRequest(name));
        return CreatedAtAction(nameof(Get), new { id }, null);
    }

    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(Guid id)
    {
        await _deleteUser.Run(new DeleteUserRequest(id));
        return NoContent();
    }
}

Each base class also defines an implicit conversion to the matching Func<> delegate, which is useful when passing a handler to code that expects a plain function:

Func<CreateUserRequest, Task<Guid>> create = new CreateUserCommand(users);

License

MIT

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

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SeaQRS:

Package Downloads
SeaQRS.Dependency

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 140 8/17/2026
1.2.0 136 8/17/2026
1.1.1 136 5/23/2026
1.1.0 163 3/16/2026
1.0.0 145 3/16/2026