Skip to main content
Table of Contents

Class CachingServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Stratara.Infrastructure.dll

DI helpers for wiring the Redis cache used by the Stratara framework.

public static class CachingServiceCollectionExtensions
Inheritance
CachingServiceCollectionExtensions
Inherited Members

Methods

AddCaching(IHostApplicationBuilder)

Registers a singleton StackExchange.Redis.IConnectionMultiplexer built from the ConnectionStrings:redis configuration entry.

public static IHostApplicationBuilder AddCaching(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Requires a connection string named redis — the call throws at start-up without one:

// appsettings.json: { "ConnectionStrings": { "redis": "localhost:6379" } }
builder.AddCaching();

Remarks

Two framework components change what they can do when this is called. A single host needs neither: AddRedisOutboxLock() in Stratara.Outbox.RabbitMQ replaces the in-process outbox lock with a Redis-leased one, which is what makes a multi-replica outbox worker safe; and the projection replay state, which every dispatching composite registers, is held in Redis when this connection exists and in process when it does not — only the Redis-backed one lets a replay requested in one host suppress publication in the others. Both take StackExchange.Redis.IConnectionMultiplexer and pick it up in whatever order the calls are made.

Before Stratara 1.x cleanup this method delegated to builder.AddRedisClient("redis") from Aspire.StackExchange.Redis, which also registered a Redis health check and OpenTelemetry instrumentation. This vendor-direct implementation does neither — consumers that need them must register them explicitly (e.g. AddHealthChecks().AddRedis(...) from AspNetCore.HealthChecks.Redis, and AddRedisInstrumentation() from OpenTelemetry.Instrumentation.StackExchangeRedis).

Exceptions

InvalidOperationException

Thrown when the redis connection string is missing.