VOOZH about

URL: https://www.nuget.org/packages/FeatureSlice/

⇱ NuGet Gallery | FeatureSlice 1.0.7




FeatureSlice 1.0.7

Prefix Reserved
dotnet add package FeatureSlice --version 1.0.7
 
 
NuGet\Install-Package FeatureSlice -Version 1.0.7
 
 
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" Version="1.0.7" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FeatureSlice" Version="1.0.7" />
 
Directory.Packages.props
<PackageReference Include="FeatureSlice" />
 
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 FeatureSlice --version 1.0.7
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FeatureSlice, 1.0.7"
 
 
#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 FeatureSlice@1.0.7
 
 
#: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=FeatureSlice&version=1.0.7
 
Install as a Cake Addin
#tool nuget:?package=FeatureSlice&version=1.0.7
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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:

Endpoint

public sealed record ExampleHandler() : FeatureSlice<ExampleHandler.Request, ExampleHandler.Response>
(
 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"))
)
{
 public sealed record Request(string Value0, int Value1, int Value2);
 public sealed record Response(int Value0, int Value1, string Value2);
}

CronJob


public sealed record ExampleHandler() : FeatureSlice<ExampleHandler.Request, ExampleHandler.Response>
(
 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)
 )
)
{
 public sealed record Request(string Value0, int Value1, int Value2);
 public sealed record Response(int Value0, int Value1, string Value2);
}

Consumer

public sealed record ExampleConsumer() : FeatureSlice<ExampleConsumer.Request>
(
 Handle(static async (Request request, Dependency1 dep1, ExampleHandler dep2) => 
 {
 Console.WriteLine($"Consumer: {request}");

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

 await Task.CompletedTask;

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

CLI

public sealed record ExampleHandler() : FeatureSlice<ExampleHandler.Request, ExampleHandler.Response>
(
 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) 
 )
)
{
 public sealed record Request(string Value0, int Value1, int Value2);
 public sealed record Response(int Value0, int Value1, string Value2);
}

Combination of all of those


public sealed record ExampleConsumer() : FeatureSlice<ExampleConsumer.Request>
(
 Handle(static async (Request request, Dependency1 dep1, ExampleHandler dep2) => 
 {
 Console.WriteLine($"Consumer: {request}");

 await dep2.Dispatch(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"))

 .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) 
 )
)
{
 public sealed record Request(string Value0, int Value1, int Value2);
 public sealed record Response(int Value0, int Value1, string Value2);
}

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

public static void Use
(
 ExampleConsumer consumer,
 ExampleHandler handler
)
{
 consumer.Dispatch(new ExampleConsumer.Request("testConsumer", 1));
 handler.Dispatch(new ExampleHandler.Request("testHandler", 2, 3));
}

FeatureSlices Expose Register for DI registration

public static void Register(IServiceCollection services, string[] args)
{
 services.AddFeatureSlices()
 .DefaultConsumerDispatcher()
 .DefaultDispatcher()
 .MapCli(args);

 services.AddFeatureSlice<ExampleHandler>();
 services.AddFeatureSlice<ExampleConsumer>();
}
Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (1)

Showing the top 1 NuGet packages that depend on FeatureSlice:

Package Downloads
FeatureSlice.FluentServiceBus

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 213 8/1/2024
1.0.6 202 7/30/2024
1.0.5 190 7/30/2024
1.0.4 200 7/22/2024
1.0.3 227 4/6/2024
1.0.2 236 3/6/2024
1.0.1 224 2/23/2024
1.0.0 267 2/14/2024