Commandor 1.0.0

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

Commandor.Example

This package provides an example implementation of the Commandor CQRS framework. It demonstrates how to use the framework to build a RESTful API with proper CQRS patterns.

Features

  • Complete example of CQRS implementation
  • RESTful API endpoints
  • Proper error handling
  • Input validation
  • Swagger/OpenAPI documentation
  • Dependency injection setup
  • Example commands and queries
  • Example handlers and validators

Getting Started

  1. Install the package:
dotnet add package Commandor.Example
  1. Add the required services in your Program.cs:
// Add CQRS services
builder.Services.AddCommandor();

// Register query handlers
builder.Services.AddScoped<IQueryHandler<GetProductsQuery, Result<IEnumerable<Product>>>, GetProductsQueryHandler>();
builder.Services.AddScoped<IQueryHandler<GetProductQuery, Result<Product>>, GetProductQueryHandler>();

// Register validators
builder.Services.AddScoped<IValidator<GetProductsQuery>, GetProductsQueryValidator>();
builder.Services.AddScoped<IValidator<GetProductQuery>, GetProductQueryValidator>();

// Register validation behavior
builder.Services.AddScoped(typeof(IPipelineBehavior<GetProductsQuery, Result<IEnumerable<Product>>>), typeof(ValidationBehavior<GetProductsQuery, Result<IEnumerable<Product>>>));
builder.Services.AddScoped(typeof(IPipelineBehavior<GetProductQuery, Result<Product>>), typeof(ValidationBehavior<GetProductQuery, Result<Product>>));
  1. Define your endpoints:
app.MapGet("/products", async (IEnumerable<string>? ids, IDispatcher dispatcher) =>
{
    var query = new GetProductsQuery { Ids = ids };
    var result = await dispatcher.SendAsync<IEnumerable<Product>>(query);
    return result.IsSuccess 
        ? Results.Ok(result.Value) 
        : Results.BadRequest(new ErrorResponse(result.Error));
});

Example Usage

Commands

// Create a command
var command = new CreateProductCommand 
{ 
    Name = "Example Product",
    Price = 99.99m
};

// Send the command
var result = await dispatcher.SendAsync<string>(command);

Queries

// Create a query
var query = new GetProductQuery { Id = "123" };

// Send the query
var result = await dispatcher.SendAsync<Product>(query);

Error Handling

The example includes proper error handling with consistent error responses:

public sealed record ErrorResponse(string Error);

Validation

Input validation is handled using FluentValidation:

public sealed class GetProductQueryValidator : AbstractValidator<GetProductQuery>
{
    public GetProductQueryValidator()
    {
        RuleFor(x => x.Id)
            .NotEmpty()
            .WithMessage("Product ID is required");
    }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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 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
1.0.0 155 5/22/2025