95 lines
3.5 KiB
C#
95 lines
3.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace StellaOps.Provcache;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering Provcache services.
|
|
/// </summary>
|
|
public static class ProvcacheServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds Provcache services to the service collection.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configuration">The configuration section.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddProvcache(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
|
|
// Register options
|
|
services.Configure<ProvcacheOptions>(configuration.GetSection(ProvcacheOptions.SectionName));
|
|
|
|
// Register core services
|
|
services.AddSingleton<IProvcacheService, ProvcacheService>();
|
|
|
|
// Register write-behind queue as hosted service
|
|
services.AddSingleton<WriteBehindQueue>();
|
|
services.AddSingleton<IWriteBehindQueue>(sp => sp.GetRequiredService<WriteBehindQueue>());
|
|
services.AddHostedService(sp => sp.GetRequiredService<WriteBehindQueue>());
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds Provcache services with custom options.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configure">Action to configure options.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddProvcache(
|
|
this IServiceCollection services,
|
|
Action<ProvcacheOptions> configure)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configure);
|
|
|
|
// Register options
|
|
services.Configure(configure);
|
|
|
|
// Register core services
|
|
services.AddSingleton<IProvcacheService, ProvcacheService>();
|
|
|
|
// Register write-behind queue as hosted service
|
|
services.AddSingleton<WriteBehindQueue>();
|
|
services.AddSingleton<IWriteBehindQueue>(sp => sp.GetRequiredService<WriteBehindQueue>());
|
|
services.AddHostedService(sp => sp.GetRequiredService<WriteBehindQueue>());
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the Valkey-backed cache store implementation.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddProvcacheValkeyStore(this IServiceCollection services)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
// Note: Actual Valkey store implementation would be registered here
|
|
// services.AddSingleton<IProvcacheStore, ValkeyProvcacheStore>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the Postgres repository implementation.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddProvcachePostgresRepository(this IServiceCollection services)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
// Note: Actual Postgres repository implementation would be registered here
|
|
// services.AddSingleton<IProvcacheRepository, PostgresProvcacheRepository>();
|
|
|
|
return services;
|
|
}
|
|
}
|