diff --git a/src/Microsoft.FeatureManagement/FeatureManagementBuilderExtensions.cs b/src/Microsoft.FeatureManagement/FeatureManagementBuilderExtensions.cs index 162a6cce..c4705c3e 100644 --- a/src/Microsoft.FeatureManagement/FeatureManagementBuilderExtensions.cs +++ b/src/Microsoft.FeatureManagement/FeatureManagementBuilderExtensions.cs @@ -16,6 +16,29 @@ namespace Microsoft.FeatureManagement /// public static class FeatureManagementBuilderExtensions { + /// + /// Adds an to be used for targeting and registers the targeting filter to the feature management system. + /// + /// The used to customize feature management functionality. + /// A that can be used to customize feature management functionality. + public static IFeatureManagementBuilder WithTargeting(this IFeatureManagementBuilder builder) where T : ITargetingContextAccessor + { + // + // Register the targeting context accessor with the same lifetime as the feature manager + if (builder.Services.Any(descriptor => descriptor.ServiceType == typeof(IFeatureManager) && descriptor.Lifetime == ServiceLifetime.Scoped)) + { + builder.Services.TryAddScoped(typeof(ITargetingContextAccessor), typeof(T)); + } + else + { + builder.Services.TryAddSingleton(typeof(ITargetingContextAccessor), typeof(T)); + } + + builder.AddFeatureFilter(); + + return builder; + } + /// /// Adds a telemetry publisher to the feature management system. /// @@ -42,28 +65,5 @@ private static IFeatureManagementBuilder AddTelemetryPublisher(this IFeatureMana return builder; } - - /// - /// Adds an to be used for targeting and registers the targeting filter to the feature management system. - /// - /// The used to customize feature management functionality. - /// A that can be used to customize feature management functionality. - public static IFeatureManagementBuilder WithTargeting(this IFeatureManagementBuilder builder) where T : ITargetingContextAccessor - { - // - // Register the targeting context accessor with the same lifetime as the feature manager - if (builder.Services.Any(descriptor => descriptor.ServiceType == typeof(IFeatureManager) && descriptor.Lifetime == ServiceLifetime.Scoped)) - { - builder.Services.TryAddScoped(typeof(ITargetingContextAccessor), typeof(T)); - } - else - { - builder.Services.TryAddSingleton(typeof(ITargetingContextAccessor), typeof(T)); - } - - builder.AddFeatureFilter(); - - return builder; - } } }