using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StellaOps.Infrastructure.Postgres.Options;
using StellaOps.Scheduler.Models;
using StellaOps.Scheduler.Persistence.Postgres;
using StellaOps.Scheduler.Persistence.Postgres.Repositories;
namespace StellaOps.Scheduler.Persistence.Extensions;
///
/// Extension methods for configuring Scheduler persistence services.
///
public static class SchedulerPersistenceExtensions
{
///
/// Adds Scheduler PostgreSQL persistence services using configuration section.
///
/// Service collection.
/// Configuration root.
/// Configuration section name for PostgreSQL options.
/// Service collection for chaining.
public static IServiceCollection AddSchedulerPersistence(
this IServiceCollection services,
IConfiguration configuration,
string sectionName = "Postgres:Scheduler")
{
services.Configure(sectionName, configuration.GetSection(sectionName));
services.AddSingleton();
// Register repositories
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddSingleton();
return services;
}
///
/// Adds Scheduler PostgreSQL persistence services with explicit options.
///
/// Service collection.
/// Options configuration action.
/// Service collection for chaining.
public static IServiceCollection AddSchedulerPersistence(
this IServiceCollection services,
Action configureOptions)
{
services.Configure(configureOptions);
services.AddSingleton();
// Register repositories
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
return services;
}
}