Table of Contents

Class DaprCacheExtension

Namespace
Arc4u.Configuration.Dapr
Assembly
Arc4u.Caching.dll

Extension methods to register the options of a Dapr state store cache.

public static class DaprCacheExtension
Inheritance
DaprCacheExtension
Inherited Members

Methods

AddDaprCache(IServiceCollection, string, IConfiguration, string)

Registers the options of the Dapr cache with the given name from a configuration section. Nothing is registered when the section does not exist. Only Name is read from the section: use the other overload to set JsonSerializerOptions.

public static IServiceCollection AddDaprCache(this IServiceCollection services, string name, IConfiguration configuration, string sectionName)

Parameters

services IServiceCollection

The service collection.

name string

The name of the cache, as used in Name.

configuration IConfiguration

The application configuration.

sectionName string

The path of the section that holds the DaprCacheOption values.

Returns

IServiceCollection

The same IServiceCollection, for chaining.

Exceptions

ArgumentException

name is null or empty and the section exists.

AddDaprCache(IServiceCollection, string, Action<DaprCacheOption>)

Registers the options of the Dapr cache with the given name.

public static IServiceCollection AddDaprCache(this IServiceCollection services, string name, Action<DaprCacheOption> options)

Parameters

services IServiceCollection

The service collection.

name string

The name of the cache, as used in Name.

options Action<DaprCacheOption>

The action that configures the options.

Returns

IServiceCollection

The same IServiceCollection, for chaining.

Examples

builder.Services.AddDaprCache("Shared", o => o.Name = "statestore");

// In a native AOT application, give the metadata of the cached types.
builder.Services.AddDaprCache("Shared", o =>
{
    o.Name = "statestore";
    o.JsonSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web) { TypeInfoResolver = AppJsonContext.Default };
});

Exceptions

ArgumentException

name is null or empty.