Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.Outbox

L3StableNuGet: v3.0.0Local HEAD: v4.2.0AOT: Partial

Install EricksonLopez.Outbox along with a storage backend (such as EricksonLopez.Outbox.Storage.PostgreSql) and broker adapter (3.0.0 on NuGet).

dotnet add package EricksonLopez.Outbox --version 3.0.0
Terminal window
dotnet add package EricksonLopez.Outbox.Storage.PostgreSql --version 3.0.0
dotnet add package EricksonLopez.Outbox.Brokers.RabbitMQ --version 3.0.0
dotnet add package EricksonLopez.Outbox.SourceGenerators --version 3.0.0

Publication Note: EricksonLopez.Inbox.PostgreSql and EricksonLopez.Outbox.OpenTelemetry exist only in local 4.2.0 HEAD and are not published on NuGet.org.

AddOutbox() lives in namespace EricksonLopez.Outbox.Hosting; and registers OutboxStartupValidator, which requires ILogger<OutboxStartupValidator>, an IOutboxSerializer, an IOutboxMessageTypeResolver, and an IOutboxRepository:

using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using EricksonLopez.Outbox;
using EricksonLopez.Outbox.Contracts;
using EricksonLopez.Outbox.Hosting;
using EricksonLopez.Outbox.Serialization;
using EricksonLopez.Outbox.Storage.PostgreSql;
using Microsoft.Extensions.DependencyInjection;
namespace Example.OutboxQuickStart;
[OutboxMessage("orders.placed")]
public sealed record OrderPlacedEvent(Guid OrderId, decimal Total);
[JsonSerializable(typeof(OrderPlacedEvent))]
public sealed partial class OutboxJsonContext : JsonSerializerContext;
public sealed class ConsoleBrokerPublisher : IBrokerPublisher
{
public ValueTask<DispatchResult> PublishRawAsync(
OutboxMessage message,
OutboxMessageMetadata metadata,
DispatchContext context)
=> ValueTask.FromResult(DispatchResult.Ok());
}
public static class OutboxUsage
{
public static void Register()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddOutbox(options =>
{
options.UsePostgreSql("Host=localhost;Database=app;Username=postgres;Password=postgres");
options.UseSerializer(new NativeAotJsonSerializer(OutboxJsonContext.Default));
options.UseTypeResolver(new InMemoryMessageTypeResolver(
[
("orders.placed", typeof(OrderPlacedEvent)),
]));
options.UseBroker<ConsoleBrokerPublisher>();
});
using var provider = services.BuildServiceProvider(
new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
using var scope = provider.CreateScope();
var outbox = scope.ServiceProvider.GetRequiredService<IOutbox>();
if (outbox is null)
{
throw new InvalidOperationException("IOutbox was not resolved.");
}
}
}