using Bit.Core.AdminConsole.OrganizationFeatures.Policies.Implementations; using Bit.Core.AdminConsole.OrganizationFeatures.Policies.PolicyRequirements; using Bit.Core.AdminConsole.OrganizationFeatures.Policies.PolicyValidators; using Bit.Core.AdminConsole.Services; using Bit.Core.AdminConsole.Services.Implementations; using Microsoft.Extensions.DependencyInjection; namespace Bit.Core.AdminConsole.OrganizationFeatures.Policies; public static class PolicyServiceCollectionExtensions { public static void AddPolicyServices(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddPolicyValidators(); services.AddPolicyRequirements(); } private static void AddPolicyValidators(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); } private static void AddPolicyRequirements(this IServiceCollection services) { // Register policy requirement factories here services.AddPolicyRequirement(SendPolicyRequirement.Create); } /// /// Used to register simple policy requirements where its factory method implements CreateRequirement. /// This MUST be used rather than calling AddScoped directly, because it will ensure the factory method has /// the correct type to be injected and then identified by at runtime. /// /// The specific PolicyRequirement being registered. private static void AddPolicyRequirement(this IServiceCollection serviceCollection, RequirementFactory factory) where T : class, IPolicyRequirement => serviceCollection.AddPolicyRequirement(_ => factory); /// /// Used to register policy requirements where you need to access additional dependencies (usually to return a /// curried factory method). /// This MUST be used rather than calling AddScoped directly, because it will ensure the factory method has /// the correct type to be injected and then identified by at runtime. /// /// /// A callback that takes IServiceProvider and returns a RequirementFactory for /// your policy requirement. /// private static void AddPolicyRequirement(this IServiceCollection serviceCollection, Func> factory) where T : class, IPolicyRequirement => serviceCollection.AddScoped>(factory); }