DKNet.SlimBus.Extensions
9.0.2
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
<PackageReference Include="DKNet.SlimBus.Extensions" Version="9.0.2" />
<PackageVersion Include="DKNet.SlimBus.Extensions" Version="9.0.2" />
<PackageReference Include="DKNet.SlimBus.Extensions" />
paket add DKNet.SlimBus.Extensions --version 9.0.2
#r "nuget: DKNet.SlimBus.Extensions, 9.0.2"
#:package DKNet.SlimBus.Extensions@9.0.2
#addin nuget:?package=DKNet.SlimBus.Extensions&version=9.0.2
#tool nuget:?package=DKNet.SlimBus.Extensions&version=9.0.2
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 usingIEventHandler
.
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
- Framework: .NET 9.0
- Dependencies:
- FluentResults: Result handling.
- Microsoft.EntityFrameworkCore.Abstractions: EF Core support.
- SlimMessageBus: Lightweight message bus library.
Installation
Add the NuGet Package:
dotnet add package DKNet.SlimBus.Extensions
Configure Dependency Injection: In your application startup, add SlimMessageBus and EF Core integration:
services.AddSlimBusForEfCore(busConfig => { // SlimMessageBus configuration here });
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 methodAddSlimBusForEfCore
for DI registration.Behaviors/EfAutoSavePostProcessor.cs
: ImplementsIRequestHandlerInterceptor
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 | Versions 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. |
-
net9.0
- DKNet.EfCore.Repos (>= 9.0.2)
- FluentResults (>= 3.16.0)
- Meziantou.Analyzer (>= 2.0.202)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.6)
- SlimMessageBus (>= 3.0.0)
- SlimMessageBus.Host (>= 3.2.0)
- SlimMessageBus.Host.Interceptor (>= 3.0.0)
- X.PagedList (>= 10.5.7)
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 |