NotableDateCacheWarmupExtensions Class
Definition
- Namespace
- Bodu.Globalization.Calendar
- Assembly
- Bodu.Globalization.Calendar.Caching.dll
- Package
- Bodu.Globalization.Calendar.Caching 1.0.0
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
servicesIServiceCollectionThe service collection to modify.
configurationIConfigurationAn optional configuration root or section bound into NotableDateCacheWarmupOptions.
sectionNamestringThe configuration section name. Defaults to
Calendar:NotableDateCacheWarmup.configureAction<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
servicesis null.- ArgumentException
Thrown when
sectionNameis empty or white space.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |