rebar.core 1.4.2

dotnet add package rebar.core --version 1.4.2
NuGet\Install-Package rebar.core -Version 1.4.2
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="rebar.core" Version="1.4.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add rebar.core --version 1.4.2
#r "nuget: rebar.core, 1.4.2"
#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.
// Install rebar.core as a Cake Addin
#addin nuget:?package=rebar.core&version=1.4.2

// Install rebar.core as a Cake Tool
#tool nuget:?package=rebar.core&version=1.4.2

license nuget downloads

rebar.core

NuGet library to support CQS pattern based project with Autofac implementation

Note

Library is created for personal purposes but I decided that it can get useful for someone else so feel free to use.

Features

Library allows to provide simple command query separation inside project using AutoFac library.

Examples

Commands

Commands are executed without results in return.

Namespace
using Rebar.Core.Command
Execute
private ICommandDispatcher _dispatcher;

public Execute(ICommandDispatcher dispatcher)
{
    _dispatcher = dispatcher;
}

...

var command = new SampleCommand("John");
_dispatcher.Execute(command);

SampleCommand.cs
public class SampleCommand : ICommand
{
    public string Name { get; set; }
  
    public SampleCommand(string name)
    {
        this.Name = name;
    }
}
SampleCommandHandler.cs
public class SampleCommandHandler : ICommandHandler<SampleCommand>
{
    public void Execute(SampleCommand command)
    {
        command.Name // John
        ...
    }
}

Queries

Queries are executed and return defined class object

Namespace
using Rebar.Core.Query
Execute
private IQueryDispatcher _dispatcher
public Execute(IQueryDispatcher dispatcher)
{
    _dispatcher = dispatcher;
}

...
var query = new SampleQuery(10);
var result = _dispatcher.Execute(query); // result = { SubstractionResult: 4 }
SampleQuery.cs
public class SampleQuery : IQuery<SampleQueryResponse>
{
    public int BaseNumber { get; set; }
  
    public SampleQuery(int number)
    {
        this.BaseNumber = number;
    }
}
SampleQueryResponse.cs
public class SampleQueryResponse : IQueryResponse
{
    public int SubstractionResult { get; set; }
  
    public SampleQueryResponse(int result) 
    {
        this.SubstractionResult = result;
    }
}
SampleQueryResponseHandler.cs
public class SampleQueryResponseHandler : IQueryHandler<SampleQuery, SampleQueryResponse>

public SampleQueryResponse Execute(SampleQuery query)
{
    var substraction = query.BaseNumber - 6;
    return new SampleQueryResponse(substraction);
}

Async operations

Commands

ICommandHandler<ICommand> => IAsyncCommandHandler<ICommand>
public class SampleCommandHandler : IAsyncCommandHandler<SampleCommand>
{
    public void ExecuteAsync(SampleCommand command, CancellationToken token) {}
}

...

_dispatcher.ExecuteAsync(command);

Queries

IQueryHandler<IQuery, IQueryResponse> => IAsyncQueryHandler<IQuery, IQueryResponse>
public class SampleQueryResponseHandler : IAsyncQueryHandler<SampleQuery, SampleQueryResponse>
{
    public Task<SampleQueryResponse> ExecuteAsync(SampleQuery query, CancellationToken token) {}
}

...

_dispatcher.ExecuteAsync(query);

Configuration

In startup.cs include following line to include Rebar.Core in service collection.

using Rebar.Core.Extensions;
...
builder.AddRebarCore();

Next in AutoFac module files declare registering commands and/or queries.

Important: Handlers are name sensitive. They should end with "QueryHandler" or "CommandHandler" otherwise they won't be recognized.

public class AppModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        var executingAssembly = GetExecutingAssembly();
        
        // register commands within assembly
        builder.RegisterCommandHandlers(executingAssembly);
        
        // register queries within assembly
        builder.RegisterQueryHandlers(executingAssembly);
        
        // register both queries and commands within assembly
        builder.RegisterAll(executingAssembly);
    }
 }

Methods

ContainerBuilder RegisterCommandHandlers(self ContainerBuilder builder, ExecutingAssembly assembly, InstanceTypes instanceType, object[] lifeTimeScopeTags)

Registers commands within assembly.

Parameters
  • builder ContainerBuilder <br> Extension for AutoFac ContainerBuilder <br> <br>
  • assembly ExecutingAssembly <br> Assembly that contains commands definitions. <br> <br>
  • (optional ) instanceType InstanceTypes <br> Instance lifecycle type for commands. <br> default value: InstanceTypes.LifetimeScope <br> <br>
  • (optional) lifeTimeScopeTags object[] <br> Tag applied to matching lifetime scopes. Optional for request scope, required for matching lifetime scope. <br> default: null <br> <br>
ContainerBuilder RegisterQueryHandlers(self ContainerBuilder builder, ExecutingAssembly assembly, InstanceTypes instanceType, object[] lifeTimeScopeTags)

Registers queries within assembly.

Parameters
  • builder ContainerBuilder <br> Extension for AutoFac ContainerBuilder <br> <br>
  • assembly ExecutingAssembly <br> Assembly that contains query definitions. <br> <br>
  • (optional ) instanceType InstanceTypes <br> Instance lifecycle type for query. <br> default value: InstanceTypes.LifetimeScope <br> <br>
  • (optional) lifeTimeScopeTags object[] <br> Tag applied to matching lifetime scopes. Optional for request scope, required for matching lifetime scope. <br> default: null <br> <br>
ContainerBuilder RegisterAll(self ContainerBuilder builder, ExecutingAssembly assembly, InstanceTypes instanceType, object[] lifeTimeScopeTags)

Registers both commands and queries within assembly.

Parameters
  • builder ContainerBuilder <br> Extension for AutoFac ContainerBuilder <br> <br>
  • assembly ExecutingAssembly <br> Assembly that contains query definitions. <br> <br>
  • (optional ) instanceType InstanceTypes <br> Instance lifecycle type for query. <br> default value: InstanceTypes.LifetimeScope <br> <br>
  • (optional) lifeTimeScopeTags object[] <br> Tag applied to matching lifetime scopes. Optional for request scope, required for matching lifetime scope. <br> default: null
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.4.2 878 6/13/2023
1.4.1 881 6/11/2023
1.4.0 885 6/4/2023
1.3.0 1,009 11/19/2021
1.2.0 1,405 1/4/2020
1.1.0 1,456 12/19/2019
1.0.0 1,665 12/14/2019