CQRSharp 2.2.6

dotnet add package CQRSharp --version 2.2.6
                    
NuGet\Install-Package CQRSharp -Version 2.2.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="CQRSharp" Version="2.2.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CQRSharp" Version="2.2.6" />
                    
Directory.Packages.props
<PackageReference Include="CQRSharp" />
                    
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 CQRSharp --version 2.2.6
                    
#r "nuget: CQRSharp, 2.2.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.
#addin nuget:?package=CQRSharp&version=2.2.6
                    
Install CQRSharp as a Cake Addin
#tool nuget:?package=CQRSharp&version=2.2.6
                    
Install CQRSharp as a Cake Tool

CQRSharp

NuGet version (CQRSharp) CodeQL Qodana

Alt

A lightweight, extensible, and attribute-driven Command Query Responsibility Segregation (CQRS) framework for .NET applications, with complete Native AoT support.

For more information, please advise the wiki page!


Contributing

Contributions are welcome! Please open issues and pull requests for bug fixes, enhancements, or new features.

To contribute:

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes.
  4. Submit a pull request.

Please ensure that your code follows the project's coding standards and includes appropriate tests.


License

This project is licensed under the MIT License.


Note: This project is in active development.

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.  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 is compatible. 
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 2.2.6 (2025‑04‑20)
           
           Breaking Changes
           - `QueueBackgroundWorkItemAsync` now returns `Task<QueueWriteResult>` instead of a fire‑and‑forget `Task`.
           - `IBackgroundTaskQueue` no longer exposes `OnTaskEnqueued`/`OnTaskRejected` events; use the notification channel.
           - `BackgroundTaskQueue.DequeueAsync` signature changed to `ValueTask<QueuedTask>`.
           - `BackgroundTaskQueueOptions.DequeueBatchSize` deprecated in favor of `CallbackChannelCapacity` and `ShutdownTimeout`.
           - All `.ContinueWith` usage in the Dispatcher was replaced by `async`/`await`, preserving stack traces and the `SynchronizationContext`.
           
           Added
           - **Dispatcher**: `EnqueueAndWatchAsync` helper; simplified `finalHandlerWrapper` logic.
           - **DI Extensions**: `CqrsStartupLogger` (`IHostedService`) & `CqrsRegistrationInfo` for deferred CQRS‑registration logging.
           - **RateLimiter**: `ShardedLruCache` with per‑shard LRU eviction; implements `IDisposable` to tear down the cleanup timer.
           - **BackgroundTaskQueue**:
             - `QueuedTask` struct (with `QueueId`, `SequenceNumber`, `EnqueueTime`) and `QueueWriteResult` struct.
             - Built‑in metrics: `TotalItemsEnqueued`, `TotalDroppedNewest`, `TotalDroppedOldest`.
             - Dedicated notification channel via `INotificationDispatcher`.
             - `CountingChannelReader` for atomic queue‑depth tracking.
           - **BackgroundTaskQueueConsumer**: single loop gated by a `SemaphoreSlim` (`ConsumerCount`); lifecycle logging; `ShutdownTimeout` support.
           
           Changed
           - **Dispatcher**: `ExecuteCommand` now returns a `Task` immediately in async mode.
           - **RateLimiter**:
             - Corrected refill formula to apply `replenishRatePerSecond` directly.
             - High‑precision timing via `Stopwatch.GetTimestamp()`.
             - Sliding‑expiration cleanup via explicit snapshot and background timer.
           - **BackgroundTaskQueue**:
             - Consolidated multi‑shard design into a single bounded `Channel<QueuedTask>`.
             - Explicit implementation of all `BoundedChannelFullMode` policies (`Wait`, `DropNewest`, `DropOldest`, `Throw`).
             - Replaced manual `WaitToReadAsync` and`TryRead` loops with `ReadAllAsync()`.
             - Refactored notification dispatch into `ProcessNotificationsAsync` with retry parameters.
           
           Removed
           - All `.ContinueWith` calls; static CQRS‑registrar logging at DI setup.
           - Third‑party/`MemoryCache` dependencies in `RateLimiter`.
           - Busy‑wait loops and redundant `Task.Run` calls in the background queue.
           - Public `OnTaskEnqueued`/`OnTaskRejected` events on `IBackgroundTaskQueue`.
           
           Fixed
           - Race conditions in `DropOldest`/`DropNewest` policies under contention.
           - Cancellation and exception propagation in `Dispatcher.EnqueueAndWatchAsync`.
           - Timer leak in `RateLimiter` by implementing `Dispose`.
           - Refill‑rate drift in token‑bucket logic; restored full exception stacks by removing `.ContinueWith`.
           
           Performance
           - **Dispatcher**: end‑to‑end `await` for context‑safe execution.
           - **RateLimiter**: sharded cache + stopwatch timing for minimal contention.
           - **BackgroundTaskQueue**: single channel + `CountingChannelReader` for lock‑free depth tracking.
           - **Consumer**: `SemaphoreSlim`‑gated loop avoids thread‑pool storms.
           
           Testing
           - **DispatcherTests**: sync/async execution, cancellation, exception‑propagation coverage.
           - **RateLimiterTests**: refill accuracy, shard eviction, timer disposal.
           - **BackgroundTaskQueueTests**: backpressure modes, FIFO ordering, metrics, high‑concurrency and graceful shutdown.
           - **RequestDispatcherTests**: host‑lifetime cancellation via `TestHostApplicationLifetime`.
           - **BackgroundTaskQueueConsumerTests**: concurrency gating and lifecycle logging.
           
           Documentation
           - Updated XML docs for new options (`EnableMetrics`, `NotificationMaxRetries`, `ShutdownTimeout`, `MetricLogInterval`).
           - Clarified defaults and valid ranges in `BackgroundTaskQueueOptions` and `RateLimiterOptions`.