Table of Contents

NotableDateCachingExtensions Class

Definition

Namespace
Bodu.Globalization.Calendar
Assembly
Bodu.Globalization.Calendar.Caching.dll
Package
Bodu.Globalization.Calendar.Caching 1.0.0
Source
NotableDateCachingExtensions.cs

Provides IServiceCollection extension methods that wrap a registered INotableDateService with a caching decorator.

public static class NotableDateCachingExtensions
Inheritance
NotableDateCachingExtensions
Inherited Members

Examples

builder.Services.AddNotableDateService(AmericasCalendarData.LoadResource("US"));
builder.Services.AddCachedNotableDateService(configure: o => o.Ttl = TimeSpan.FromDays(7));

Remarks

The registration decorates the existing INotableDateService in place: the previously registered service becomes the inner service a CachingNotableDateService computes misses through, so consumers continue to inject INotableDateService and transparently gain caching. An INotableDateResourceProvider registered by AddReloadableNotableDateService is observed automatically, so a reload invalidates the cache.

Methods

AddCachedNotableDateService(IServiceCollection, IConfiguration?, string, Action<NotableDateCachingOptions>?, Func<IServiceProvider, INotableDateCache>?)

Wraps the registered INotableDateService with a caching decorator, binding the caching options from configuration.

public static IServiceCollection AddCachedNotableDateService(this IServiceCollection services, IConfiguration? configuration, string sectionName = "Calendar:NotableDateCache", Action<NotableDateCachingOptions>? configure = null, Func<IServiceProvider, INotableDateCache>? cacheFactory = null)

Parameters

services IServiceCollection

The service collection to modify.

configuration IConfiguration

An optional configuration root or section bound into the caching options.

sectionName string

The configuration section name. Defaults to Calendar:NotableDateCache.

configure Action<NotableDateCachingOptions>

An optional callback applied after configuration binding.

cacheFactory Func<IServiceProvider, INotableDateCache>

An optional factory producing the INotableDateCache. When null, a default per-territory TOML file cache is used.

Returns

IServiceCollection

The same service collection, to allow chaining.

Exceptions

ArgumentNullException

Thrown when services is null.

ArgumentException

Thrown when sectionName is empty or white space.

InvalidOperationException

Thrown when no INotableDateService has been registered.

AddCachedNotableDateService(IServiceCollection, Action<NotableDateCachingOptions>?, Func<IServiceProvider, INotableDateCache>?)

Wraps the registered INotableDateService with a caching decorator, using the supplied cache or a default per-territory TOML file cache.

public static IServiceCollection AddCachedNotableDateService(this IServiceCollection services, Action<NotableDateCachingOptions>? configure = null, Func<IServiceProvider, INotableDateCache>? cacheFactory = null)

Parameters

services IServiceCollection

The service collection to modify.

configure Action<NotableDateCachingOptions>

An optional callback applied to the caching options.

cacheFactory Func<IServiceProvider, INotableDateCache>

An optional factory producing the INotableDateCache from the service provider. When null, a default TomlNotableDateCache under the options' CacheDirectory is used. Supply a factory to choose the storage structure - for example an in-memory, JSON, SQLite, or distributed cache.

Returns

IServiceCollection

The same service collection, to allow chaining.

Exceptions

ArgumentNullException

Thrown when services is null.

InvalidOperationException

Thrown when no INotableDateService has been registered.

Applies to

ProductVersions
.NET8, 10