Table of Contents

NotableDateCacheWarmupExtensions Class

Definition

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

Provides IServiceCollection registration of the startup notable-date cache warm-up.

public static class NotableDateCacheWarmupExtensions
Inheritance
NotableDateCacheWarmupExtensions
Inherited Members

Methods

AddNotableDateCacheWarmup(IServiceCollection, IConfiguration?, string, Action<NotableDateCacheWarmupOptions>?)

Registers a hosted service that warms the caching notable-date service at application start, resolving the configured territories over the configured span of civil years through the normal read-through path so the first user request never pays the year computation.

public static IServiceCollection AddNotableDateCacheWarmup(this IServiceCollection services, IConfiguration? configuration = null, string sectionName = "Calendar:NotableDateCacheWarmup", Action<NotableDateCacheWarmupOptions>? configure = null)

Parameters

services IServiceCollection

The service collection to modify.

configuration IConfiguration

An optional configuration root or section bound into NotableDateCacheWarmupOptions.

sectionName string

The configuration section name. Defaults to Calendar:NotableDateCacheWarmup.

configure Action<NotableDateCacheWarmupOptions>

An optional callback applied after configuration binding.

Returns

IServiceCollection

The same service collection, to allow chaining.

Examples

builder.Services.AddNotableDateService(AmericasCalendarData.LoadResource("US"));
builder.Services.AddCachedNotableDateService();
builder.Services.AddNotableDateCacheWarmup(configure: warmup =>
{
    warmup.Territories.Add("US");
    warmup.Territories.Add("US-CA");
    warmup.YearsAhead = 2;
});

Remarks

The warm-up runs in the background after the host starts and never blocks or crashes it: a failing territory is logged and skipped, and host shutdown cancels the run between territories. Register it after AddCachedNotableDateService; when the resolved INotableDateService is not the caching decorator the run logs the misconfiguration and no-ops. Options are validated at application start.

Exceptions

ArgumentNullException

Thrown when services is null.

ArgumentException

Thrown when sectionName is empty or white space.

Applies to

ProductVersions
.NET8, 10