DKNet.SlimBus.Extensions 9.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package DKNet.SlimBus.Extensions --version 9.0.2
                    
NuGet\Install-Package DKNet.SlimBus.Extensions -Version 9.0.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="DKNet.SlimBus.Extensions" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.SlimBus.Extensions" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.SlimBus.Extensions" />
                    
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 DKNet.SlimBus.Extensions --version 9.0.2
                    
#r "nuget: DKNet.SlimBus.Extensions, 9.0.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.
#:package DKNet.SlimBus.Extensions@9.0.2
                    
#: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=DKNet.SlimBus.Extensions&version=9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.SlimBus.Extensions&version=9.0.2
                    
Install as a Cake Tool

DKNet.SlimBus.Extensions

Overview

The DKNet.SlimBus.Extensions project is a .NET library designed to extend the functionality of SlimMessageBus with integrations for Entity Framework Core (EF Core). It simplifies message-based communication and automates database operations for applications using the SlimMessageBus framework.


Features and Functionality

Core Features

  • Fluent Definitions: Provides reusable abstractions for request, query, and notification patterns.

    • Requests: Interfaces for handling commands (INoResponse, IWitResponse).
    • Queries: Support for paginated and standard query patterns (IWitResponse, IWitPageResponse).
    • Notifications: Notification handling using IEventHandler.
  • EF Core Integration:

    • EfAutoSavePostProcessor: Automatically saves changes in EF Core contexts after a successful request or query.
  • Service Registration:

    • AddSlimBusForEfCore: A setup method to register SlimMessageBus with EF Core in your dependency injection container.

Behaviors

  • Automatic Persistence: Ensures that database changes tracked by EF Core are saved automatically after handling requests.
  • Customizable Interceptors: Implements IRequestHandlerInterceptor to enable middleware behavior for message handling.

Requirements


Installation

  1. Add the NuGet Package:

    dotnet add package DKNet.SlimBus.Extensions
    
  2. Configure Dependency Injection: In your application startup, add SlimMessageBus and EF Core integration:

    services.AddSlimBusForEfCore(busConfig =>
    {
        // SlimMessageBus configuration here
    });
    
  3. Ensure EF Core Contexts are Registered: Ensure all DbContext instances used in your application are registered in the dependency injection container.


Project Structure

  • Fluent.cs: Defines fluent abstractions for SlimMessageBus patterns (requests, queries, notifications).
  • SlimBusEfCoreSetup.cs: Contains the setup method AddSlimBusForEfCore for DI registration.
  • Behaviors/EfAutoSavePostProcessor.cs: Implements IRequestHandlerInterceptor to handle automatic database saving after processing.

Design Highlights

  • Domain-Driven Design (DDD): Encapsulates request, query, and notification patterns in well-defined interfaces.
  • CQRS Support: Enables separation of commands and queries with SlimMessageBus.
  • Extensibility: Built to allow additional behaviors by leveraging SlimMessageBus interceptors.

Usage

Fluents Class Samples

Requests

Define a command request without a response:

public class CreateOrderRequest : Fluents.Requests.INoResponse { }

public class CreateOrderHandler : Fluents.RequestHandlers.INoResponse<CreateOrderRequest>
{
    public Task<IResultBase> Handle(CreateOrderRequest request, CancellationToken cancellationToken)
    {
        // Handle request logic
        return Task.FromResult(Result.Ok() as IResultBase);
    }
}

Define a request with a response:

public class GetOrderRequest : Fluents.Requests.IWitResponse<OrderDto>
{
    public int OrderId { get; set; }
}

public class GetOrderHandler : Fluents.RequestHandlers.IWitResponse<GetOrderRequest, OrderDto>
{
    public Task<IResult<OrderDto>> Handle(GetOrderRequest request, CancellationToken cancellationToken)
    {
        // Handle logic to get order details
        var order = new OrderDto { OrderId = request.OrderId, Status = "Completed" };
        return Task.FromResult(Result.Ok(order));
    }
}
Queries

Define a paginated query:

public class ListOrdersQuery : Fluents.Queries.IWitPageResponse<OrderDto>
{
    public int PageNumber { get; set; }
    public int PageSize { get; set; }
}

public class ListOrdersHandler : Fluents.QueryHandlers.IWitPageResponse<ListOrdersQuery, OrderDto>
{
    public Task<IPageable<OrderDto>> Handle(ListOrdersQuery query, CancellationToken cancellationToken)
    {
        // Handle logic to get paginated results
        var orders = new Pageable<OrderDto>(
            new List<OrderDto> { new() { OrderId = 1, Status = "Pending" } },
            totalCount: 100
        );
        return Task.FromResult<IPageable<OrderDto>>(orders);
    }
}
Notifications

Define and handle a notification:

public class OrderCreatedEvent { public int OrderId { get; set; } }

public class OrderCreatedEventHandler : Fluents.Notifications.IEventHandler<OrderCreatedEvent>
{
    public Task Handle(OrderCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Handle notification logic
        Console.WriteLine($"Order {notification.OrderId} created.");
        return Task.CompletedTask;
    }
}

Issues and Support

If you encounter any issues or have feature requests, please open a ticket on the project repository. Provide the following:

  • A description of the issue or request.
  • Steps to reproduce (if applicable).
  • Environment details (e.g., .NET version).

License

This project is licensed under the MIT License.


Acknowledgments

Special thanks to contributors and the developers of SlimMessageBus and FluentResults for enabling robust messaging and result handling.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
9.0.20 141 7/15/2025
9.0.19 130 7/14/2025
9.0.18 132 7/14/2025
9.0.17 130 7/14/2025
9.0.16 111 7/11/2025
9.0.15 113 7/11/2025
9.0.14 114 7/11/2025
9.0.13 122 7/11/2025
9.0.12 138 7/8/2025
9.0.11 134 7/8/2025
9.0.10 130 7/7/2025
9.0.9 135 7/2/2025
9.0.8 136 7/2/2025
9.0.7 137 7/1/2025
9.0.6 130 6/30/2025
9.0.5 141 6/24/2025
9.0.4 135 6/24/2025
9.0.3 133 6/23/2025
9.0.2 140 6/23/2025
9.0.1 140 6/23/2025