PiscesMetadata.CQRS 1.0.1

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

PiscesMetadata.CQRS

PiscesMetadata.CQRS is a lightweight C# library designed to facilitate efficient implementation of the Command Query Responsibility Segregation (CQRS) pattern in Domain-Driven Design (DDD) projects.

Features

  • Streamlined CQRS implementation
  • Robust support for events and commands
  • Seamless MongoDB integration for event storage
  • Abstract base classes for queries and commands
  • Full compatibility with .NET 8.0

Installation

You can install PiscesMetadata.CQRS via the NuGet Package Manager:

dotnet add package PiscesMetadata.CQRS

Usage

Basic Concepts

Command

A command is an instruction to perform a specific action. It is used to change the state of the system.

Query

A query is a request for information. It is used to read the state of the system.

Event

An event is a record of an action that has occurred in the system. It is used to maintain a history of actions and to notify other parts of the system of changes.

Implementing Commands and Queries

Command
public class CreateUserCommand(string name, string email, string password) : Command
{
    public override bool Validate()
    {
        return !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password);
    }

    public override void Execute()
    {
        // Implementation of the command logic
    }
}
Query
public class GetUserQuery(string userId) : Query
{
    public override bool Validate()
    {
        return !string.IsNullOrEmpty(userId);
    }

    public override object Execute()
    {
        // Implementation of the query logic
        return new { Name = "John Doe", Email = "john.doe@example.com" };
    }
}

Event

public class UserCreatedEvent(string userId, string name, string email) : Event
{
    public string UserId { get; set; } = userId;
    public string Name { get; set; } = name;
    public string Email { get; set; } = email;
}

Implementing Event Handlers

public class UserEventHandler
{
    public void Handle(UserCreatedEvent event)
    {
        // Implementation of the event handler logic
    }
}

Implementing Command Handlers

public class UserCommandHandler
{
    public void Handle(CreateUserCommand command)
    {
        // Implementation of the command handler logic
    }
}

Implementing Query Handlers

public class UserQueryHandler
{
    public object Handle(GetUserQuery query)
    {
        // Implementation of the query handler logic
        return query.Execute();
    }
}

Implementing Event Store

public class UserEventStore
{
    public void Save(UserCreatedEvent event)
    {
        // Implementation of the event store logic
    }
}

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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
1.0.1 144 9/3/2024
1.0.0 125 9/3/2024