FeatureSlice.FluentServiceBus 1.0.6

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package FeatureSlice.FluentServiceBus --version 1.0.6                
NuGet\Install-Package FeatureSlice.FluentServiceBus -Version 1.0.6                
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="FeatureSlice.FluentServiceBus" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FeatureSlice.FluentServiceBus --version 1.0.6                
#r "nuget: FeatureSlice.FluentServiceBus, 1.0.6"                
#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 FeatureSlice.FluentServiceBus as a Cake Addin
#addin nuget:?package=FeatureSlice.FluentServiceBus&version=1.0.6

// Install FeatureSlice.FluentServiceBus as a Cake Tool
#tool nuget:?package=FeatureSlice.FluentServiceBus&version=1.0.6                

FeatureSlice

Release Status NuGet Version NuGet Downloads

FeatureSlice is an library aiming to help working with Vertical/Feature Slice Architecture.

FeatureSlices contain a Handle method that can be invoked externaly by a delegate registered in DI. The method can can be extended so it can be invoked by:

  • Http Endpoint
  • Queue/Topic
  • Background Job
  • CLI

Those elements can be setup using two types of API:

Samples

Endpoint

public sealed class ExampleHandler :
    FeatureSlice<ExampleHandler, ExampleHandler.Request, ExampleHandler.Response>
{
    public sealed record Request(string Value0, int Value1, int Value2);
    public sealed record Response(int Value0, int Value1, string Value2);

    public override ISetup Setup => Handle(static async (Request request, Dependency1 dep1, Dependency2 dep2) => 
    {
        Console.WriteLine($"Handler: {request}");

        await Task.CompletedTask;

        return new Response(request.Value2, request.Value1, request.Value0);
    })
    .MapPost("handler", opt => opt
        .Request
        (
            From.Route.Int("id"),
            From.Query.Int("qu"),
            From.Body.Json<Request>(),
            (id, qu, body) => new Request(body.Value0, qu, id)
        )
        .DefaultResponse()
        .WithTags("Handler"))
}

CronJob


public sealed class ExampleHandler :
    FeatureSlice<ExampleHandler, ExampleHandler.Request, ExampleHandler.Response>
{
    public sealed record Request(string Value0, int Value1, int Value2);
    public sealed record Response(int Value0, int Value1, string Value2);

    public override ISetup Setup => Handle(static async (Request request, Dependency1 dep1, Dependency2 dep2) => 
    {
        Console.WriteLine($"Handler: {request}");

        await Task.CompletedTask;

        return new Response(request.Value2, request.Value1, request.Value0);
    })
    .MapCronJob
    (
        "5 4 * * *",
        new Request("testjob", 1, 2)
    );
}

Consumer

public sealed class ExampleConsumer :
    FeatureSlice<ExampleConsumer, ExampleConsumer.Request>
{
    public sealed record Request(string Value0, int Value1);

    public override ISetup Setup => Handle(static async (Request request, ExampleHandler.Dispatch dep2) => 
    {
        Console.WriteLine($"Consumer: {request}");

        await dep2(new ExampleHandler.Request("testFromConsumer", 0, 1));

        await Task.CompletedTask;

        return Result.Success;
    })
    .AsConsumer("ConsumerName");
}

CLI

public sealed class ExampleHandler :
    FeatureSlice<ExampleHandler, ExampleHandler.Request, ExampleHandler.Response>
{
    public sealed record Request(string Value0, int Value1, int Value2);
    public sealed record Response(int Value0, int Value1, string Value2);

    public override ISetup Setup => Handle(static async (Request request, Dependency1 dep1, Dependency2 dep2) => 
    {
        Console.WriteLine($"Handler: {request}");

        await Task.CompletedTask;

        return new Response(request.Value2, request.Value1, request.Value0);
    })
    .MapCli
    (
        Arg.Cmd("validate"),
        Arg.Opt("option1", "o1"),
        Arg.Opt("option2", "o2"),
        (arg1, arg2) => new Request(arg1, int.Parse(arg2), 5)   
    );
}

Combination of all of those


public sealed class ExampleConsumer :
    FeatureSlice<ExampleConsumer, ExampleConsumer.Request>
{
    public sealed record Request(string Value0, int Value1);

    public override ISetup Setup => Handle(static async (Request request, ExampleHandler.Dispatch dep2) => 
    {
        Console.WriteLine($"Consumer: {request}");

        await dep2(new ExampleHandler.Request("testFromConsumer", 0, 1));

        await Task.CompletedTask;

        return Result.Success;
    })
    .MapPost("consumer", opt => opt
        .Request
        (
            From.Route.Int("id"),
            From.Body.Json<Request>(),
            (id, body) => new Request(body.Value0, id)
        )
        .DefaultResponse()
        .WithTags("Consumer"))
    .AsConsumer("ConsumerName")
    .MapCronJob
    (
        "5 4 * * *",
        new Request("testjob", 1, 2)
    )
    .MapCli
    (
        Arg.Cmd("validate"),
        Arg.Opt("option1", "o1"),
        Arg.Opt("option2", "o2"),
        (arg1, arg2) => new Request(arg1, int.Parse(arg2), 5)   
    );
}

FeatureSlices Expose Dispatch methods which allow them to be called from dependencies

public static void Use
(
    ExampleConsumer.Dispatch consumer,
    ExampleHandler.Dispatch handler
)
{
    consumer(new ExampleConsumer.Request());
    handler(new ExampleHandler.Request());
}

FeatureSlices Expose Register for DI registration

public static void Register(IServiceCollection services)
{
    ExampleConsumer.Register(services);
    ExampleHandler.Register(services);
}
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. 
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.7 70 8/1/2024
1.0.6 77 7/30/2024
1.0.5 77 7/30/2024
1.0.4 87 7/22/2024
1.0.3 123 4/6/2024
1.0.2 123 3/6/2024
1.0.1 113 2/23/2024