Table of Contents

Class ServiceCollectionExtensions

Namespace
Cuemon.Extensions.AspNetCore.Configuration
Assembly
Cuemon.Extensions.AspNetCore.dll

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Examples

The following example demonstrates how to register the built-in cache-busting services and a custom ICacheBusting implementation.

using System;
using System.Linq;
using Cuemon.AspNetCore.Configuration;
using Cuemon.Extensions.AspNetCore.Configuration;
using Cuemon.Security.Cryptography;
using Microsoft.Extensions.DependencyInjection;

namespace DocfxExamples;

public class ConfigurationServiceCollectionExtensionsExample
{
    public static void ConfigureServices(IServiceCollection services)
    {
        services.AddOptions();
        services.Configure<AssemblyCacheBustingOptions>(options =>
        {
            options.Assembly = typeof(ConfigurationServiceCollectionExtensionsExample).Assembly;
            options.Algorithm = UnkeyedCryptoAlgorithm.Sha256;
            options.ReadByteForByteChecksum = true;
        });

        services.AddAssemblyCacheBusting();
        services.AddDynamicCacheBusting();
        services.AddCacheBusting<ReleaseCacheBusting>();

        var provider = services.BuildServiceProvider();
        var versions = provider.GetServices<ICacheBusting>().Select(cache => cache.Version).ToList();

        Console.WriteLine(versions.Count);
        Console.WriteLine(string.Join(", ", versions));
    }

    private sealed class ReleaseCacheBusting : ICacheBusting
    {
        public string Version => "20260618";
    }
}

Methods

AddAssemblyCacheBusting(IServiceCollection)

Adds an AssemblyCacheBusting service to the specified IServiceCollection.

public static IServiceCollection AddAssemblyCacheBusting(this IServiceCollection services)

Parameters

services IServiceCollection

The IServiceCollection to add services to.

Returns

IServiceCollection

An IServiceCollection that can be used to further configure other services.

AddCacheBusting<T>(IServiceCollection)

Adds a cache-busting service to the specified IServiceCollection.

public static IServiceCollection AddCacheBusting<T>(this IServiceCollection services) where T : class, ICacheBusting

Parameters

services IServiceCollection

The IServiceCollection to add services to.

Returns

IServiceCollection

An IServiceCollection that can be used to further configure other services.

Type Parameters

T

AddDynamicCacheBusting(IServiceCollection)

Adds a DynamicCacheBusting service to the specified IServiceCollection.

public static IServiceCollection AddDynamicCacheBusting(this IServiceCollection services)

Parameters

services IServiceCollection

The IServiceCollection to add services to.

Returns

IServiceCollection

An IServiceCollection that can be used to further configure other services.