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
servicesIServiceCollectionThe service collection.
namestringThe name of the cache, as used in Name.
configurationIConfigurationThe application configuration.
sectionNamestringThe path of the section that holds the DaprCacheOption values.
Returns
- IServiceCollection
The same IServiceCollection, for chaining.
Exceptions
- ArgumentException
nameis 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
servicesIServiceCollectionThe service collection.
namestringThe name of the cache, as used in Name.
optionsAction<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
nameis null or empty.