using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace StellaOps.Provcache;
///
/// Extension methods for registering Provcache services.
///
public static class ProvcacheServiceCollectionExtensions
{
///
/// Adds Provcache services to the service collection.
///
/// The service collection.
/// The configuration section.
/// The service collection for chaining.
public static IServiceCollection AddProvcache(
this IServiceCollection services,
IConfiguration configuration)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configuration);
// Register options
services.Configure(configuration.GetSection(ProvcacheOptions.SectionName));
// Register core services
services.AddSingleton();
// Register write-behind queue as hosted service
services.AddSingleton();
services.AddSingleton(sp => sp.GetRequiredService());
services.AddHostedService(sp => sp.GetRequiredService());
return services;
}
///
/// Adds Provcache services with custom options.
///
/// The service collection.
/// Action to configure options.
/// The service collection for chaining.
public static IServiceCollection AddProvcache(
this IServiceCollection services,
Action configure)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);
// Register options
services.Configure(configure);
// Register core services
services.AddSingleton();
// Register write-behind queue as hosted service
services.AddSingleton();
services.AddSingleton(sp => sp.GetRequiredService());
services.AddHostedService(sp => sp.GetRequiredService());
return services;
}
///
/// Adds the Valkey-backed cache store implementation.
///
/// The service collection.
/// The service collection for chaining.
public static IServiceCollection AddProvcacheValkeyStore(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
// Note: Actual Valkey store implementation would be registered here
// services.AddSingleton();
return services;
}
///
/// Adds the Postgres repository implementation.
///
/// The service collection.
/// The service collection for chaining.
public static IServiceCollection AddProvcachePostgresRepository(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
// Note: Actual Postgres repository implementation would be registered here
// services.AddSingleton();
return services;
}
}