BG.Common.Outbox 1.0.1

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

BG.Common.Outbox

Generyczny, multi-instance wzorzec Outbox. Pozwala dowolnemu modułowi/serwisowi zarejestrować własny, w pełni odizolowany OutboxProcessor (własny store, własna konfiguracja) w tym samym hoście DI — bez kolizji z innymi modułami.

Co dostarcza pakiet

  • OutboxMessage — model wiadomości outboxa.
  • IOutboxStore — abstrakcja store'a (implementuje konsument, np. EF Core).
  • IEventPublisher — abstrakcja publikacji zdarzeń (implementuje konsument).
  • OutboxProcessorOptions — konfiguracja (BatchSize, PollingInterval, LockDuration, MaxAttempts).
  • OutboxProcessor — BackgroundService odpytujący store i publikujący zdarzenia.
  • AddOutboxProcessor(...) — rejestracja jednej, nazwanej/kluczowanej instancji procesora.

Każda instancja jest identyfikowana przez key (string). Store jest resolwowany przez keyed DI (GetRequiredKeyedService<IOutboxStore>(key)), a opcje przez IOptionsMonitor<OutboxProcessorOptions>.Get(key) — dzięki temu wiele instancji OutboxProcessor może współistnieć w jednym IServiceProvider, każda ze swoim store'em i konfiguracją, bez wzajemnego nadpisywania się.

Użycie — pojedynczy moduł

services.AddKeyedScoped<IOutboxStore, MyOutboxStore>("orders");
services.AddScoped<IEventPublisher, MyEventPublisher>();

services.AddOutboxProcessor("orders", configuration, options =>
{
    options.BatchSize = 50;
});

Konfiguracja w appsettings.json (opcjonalnie, configure nadpisuje wartości z sekcji):

{
  "Outbox": {
    "Processor": {
      "orders": {
        "BatchSize": 50,
        "PollingInterval": "00:00:05",
        "LockDuration": "00:00:30",
        "MaxAttempts": 5
      }
    }
  }
}

Użycie — dwa niezależne moduły w jednym hoście

Każdy moduł rejestruje swój store pod własnym kluczem i wywołuje AddOutboxProcessor z tym samym kluczem. Procesory działają równolegle, niezależnie odpytując swoje store'y wg własnej konfiguracji:

// Moduł "orders"
services.AddKeyedScoped<IOutboxStore, OrdersOutboxStore>("orders");
services.AddOutboxProcessor("orders", configuration, o => o.BatchSize = 50);

// Moduł "notifications"
services.AddKeyedScoped<IOutboxStore, NotificationsOutboxStore>("notifications");
services.AddOutboxProcessor("notifications", configuration, o => o.BatchSize = 10);

// Wspólny publisher (lub odrębny per moduł, jeśli konsument tak zarejestruje)
services.AddScoped<IEventPublisher, EventPublisher>();

orders i notifications działają jako dwie niezależne instancje OutboxProcessor w tym samym IServiceProvider — każda korzysta wyłącznie ze swojego store'a (GetRequiredKeyedService<IOutboxStore>("orders") / "notifications") i swojej konfiguracji (IOptionsMonitor<OutboxProcessorOptions>.Get("orders") / "notifications").

Czyszczenie przetworzonych wiadomości

IOutboxStore.MarkAsProcessedAsync/MarkAsFailedAsync nie zwracają nic, co musiałoby przetrwać do późniejszego odczytu — po opublikowaniu zdarzenia nic już nie sprawdza "czy to zostało już wysłane". Dlatego, w przeciwieństwie do Inboxa (patrz niżej), w konkretnej implementacji IOutboxStore bezpiecznie można (i dla wydajności odczytu ClaimBatchAsync/wielkości tabeli — warto) fizycznie usuwać wiersz w MarkAsProcessedAsync/MarkAsFailedAsync zamiast tylko ustawiać kolumnę ProcessedAt/FailedAt. To decyzja czysto implementacyjna konkretnego store'a (EF Core/Dapper) — abstrakcja IOutboxStore już na to pozwala, nie wymaga zmian.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
1.0.1 116 7/15/2026
1.0.0 115 7/15/2026