microsoft / FeatureManagement-Dotnet

Microsoft.FeatureManagement provides standardized APIs for enabling feature flags within applications. Utilize this library to secure a consistent experience when developing applications that use patterns such as beta access, rollout, dark deployments, and more.
MIT License
1.02k stars 111 forks source link

Bug Fix - Avoid duplicated registration of TimeWindowFilter through AddFeatureFilter method #449

Closed zhiyuanliang-ms closed 3 months ago

zhiyuanliang-ms commented 3 months ago

Why this PR?

Bug fix #447

Visible change

services.AddFeatureManagement()
            .AddFeatureFilter<TimeWindowFilter>();

The call of AddFeatureFilter on the IFeatureManagementBuilder returned by the AddFeatureManagement call will no longer register TimeWindowFilter repeatedly.

This PR added a check in the AddFeatureFilter<T>() method of the FeatureManagementBuilder class, if the T is TimeWindowFilter, the method will do nothing.

All built-in feature filters are registered during the AddFeatureManagement call, the TimeWindowFilter is registered through the overload `AddFeatureFilter(Func implemenetationFactory)

The FeatureManagementBuilder is internal and only be created in the AddFeatureManagment call, this ensures that AddFeatureFilter()` will only be called after calling AddFeatureManagement() where the TimeWindowFilter should have been registered.