ArbitR 2.0.1

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

ArbitR

A simple light weight CQRS implementation built in .NET

Has support for Commands, Queries and Event notifications.

ArbitR is built on top of the .NET Service Collection, after configuration inject an IArbiter where you need it and you are good to go!

Configuration

Within a C# .NET 5 Web Applications Startup.cs or the project that contains the write/read services, read model managers & workflows.

public void ConfigureServices(IServiceCollection services)
{
    //...
    services.AddArbitR(Assembly.GetExecutingAssembly());
    //...
}

Usage

There are 4 types of services available in ArbitR.

  1. WriteService
  2. ReadService
  3. ReadModelManager
  4. Workflow (Beta)

This architecture is based off my interpretation of the Microsoft docs found here:

https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs

WriteService

Used for managing a single tables Create/Remove/Update actions. This is done through the invocation of commands. When making a command inherit ICommand.

Sample
public class ExampleWriteService : WriteService,
    IHandleCommand<ExampleCommand>
{
    /// ...
    
    public void Handle(ExampleCommand cmd)
    {
        // ...
    }
}

ReadService

Used for managing a single tables Display actions. This is done through the invocation of queries. When making a query inherit IQuery.

Sample
public class ExampleReadService : ReadService,
    IHandleQuery<ExampleQuery, ExampleModel>
{
    /// ...
    
    public ExampleModel Handle(ExampleQuery query)
    {
        // ...
    }
}

ReadModelManager

Used for managing read-only views built from one or more tables. This is done through the raising of events. When making an event, inherit IEvent.

Sample
public class LoginAttemptReadModelManager : ReadModelManager,
    IHandleEvent<LoginSuccessEvent>,
    IHandleEvent<LoginFailedEvent>,
    IHandleQuery<GetLoginAttempts, IEnumerable<LoginAttempt>>
{
    public void Handle(LoginSuccessEvent eEvent)
    {
        // Save login attempt
    }

    public void Handle(LoginFailedEvent eEvent)
    {
        // Save login attempt
    }
    
    public IEnumerable<LoginAttempt> Handle(GetLoginAttempts query)
    {
        // Get Login Attempts
    }
}

Workflow (Beta)

A workflow is meant to be an elegant way of describing a process for which Arbiter will then handle its orchestration. Use it when you need to chain together multiple commands, queries & events in a sequential order. When making a workflow, inherit Workflow<T> where T is the returned result upon success of the workflow.

Sample
public class RegisterUserWorkflow : Workflow<UserRegisteredResult>
{
    private User _user = default!;
    
    public RegisterUserWorkflow(string email, string password, string firstname, string surname)
    {
        AddStep(() => new CreateUserCommand{Email = email, Password = password, Firstname = firstname, Surname = surname})
            .OnSuccess(() => new UserCreatedEvent(email));

        AddStep(() => AuthenticateUser(email))
            .OnSuccess(() => new UserAuthenticatedEvent(firstname))
            .OnFailure(() => new UserFailedAuthenticationEvent($"{email} failed Authentication!"))
            .OnFailureThrow(e => new FailedAuthException(e));
    }
    
    public ICommand AuthenticateUser(string email)
    {
        _user = _arbiter.Invoke(new GetUserQuery(email));
        return new AuthenticateUserCommand
        {
            Email = _user.Email,
            Password = _user.Password
        };
    }
    
    public override UserRegisteredResult GetResult()
    {
        return new UserRegisteredResult(_user);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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
2.0.1 661 1/27/2022
1.0.2 486 8/23/2021