up
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Policy.Engine.Storage.Mongo.Internal;
|
||||
using StellaOps.Policy.Engine.Storage.Mongo.Migrations;
|
||||
using StellaOps.Policy.Engine.Storage.Mongo.Options;
|
||||
using StellaOps.Policy.Engine.Storage.Mongo.Repositories;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Storage.Mongo;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for registering Policy Engine MongoDB storage services.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds Policy Engine MongoDB storage services to the service collection.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <param name="configure">Optional configuration action for PolicyEngineMongoOptions.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddPolicyEngineMongoStorage(
|
||||
this IServiceCollection services,
|
||||
Action<PolicyEngineMongoOptions>? configure = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(services);
|
||||
|
||||
// Register options
|
||||
if (configure is not null)
|
||||
{
|
||||
services.Configure(configure);
|
||||
}
|
||||
|
||||
// Register context (singleton for connection pooling)
|
||||
services.AddSingleton<PolicyEngineMongoContext>();
|
||||
|
||||
// Register migrations
|
||||
services.AddSingleton<IPolicyEngineMongoMigration, EnsurePolicyCollectionsMigration>();
|
||||
services.AddSingleton<IPolicyEngineMongoMigration, EnsurePolicyIndexesMigration>();
|
||||
services.AddSingleton<IPolicyEngineMongoMigration, EnsureExceptionIndexesMigration>();
|
||||
|
||||
// Register migration runner
|
||||
services.AddSingleton<PolicyEngineMigrationRunner>();
|
||||
|
||||
// Register initializer
|
||||
services.AddSingleton<IPolicyEngineMongoInitializer, PolicyEngineMongoInitializer>();
|
||||
|
||||
// Register dynamic collection initializer for effective findings
|
||||
services.AddSingleton<IEffectiveFindingCollectionInitializer, EffectiveFindingCollectionInitializer>();
|
||||
|
||||
// Register repositories
|
||||
services.AddSingleton<IExceptionRepository, MongoExceptionRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds Policy Engine MongoDB storage services with configuration binding from a configuration section.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <param name="configuration">Configuration section containing PolicyEngineMongoOptions.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddPolicyEngineMongoStorage(
|
||||
this IServiceCollection services,
|
||||
Microsoft.Extensions.Configuration.IConfigurationSection configuration)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(services);
|
||||
ArgumentNullException.ThrowIfNull(configuration);
|
||||
|
||||
services.Configure<PolicyEngineMongoOptions>(configuration);
|
||||
|
||||
return services.AddPolicyEngineMongoStorage(configure: null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user