Skip to content

Commit fc01b24

Browse files
update
1 parent eacdb3e commit fc01b24

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/Microsoft.FeatureManagement.AspNetCore/FilterCollectionExtensions.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public static class FilterCollectionExtensions
1616
/// <typeparam name="TFilterType">The MVC filter to add and use if the feature is enabled.</typeparam>
1717
/// <param name="filters">The filter collection to add to.</param>
1818
/// <param name="feature">The feature that will need to enabled to trigger the execution of the MVC filter.</param>
19-
/// <returns></returns>
19+
/// <returns>The reference to the added filter metadata.</returns>
2020
public static IFilterMetadata AddForFeature<TFilterType>(this FilterCollection filters, string feature) where TFilterType : IAsyncActionFilter
2121
{
22-
IFilterMetadata filterMetadata = null;
22+
IFilterMetadata filterMetadata = new FeatureGatedAsyncActionFilter<TFilterType>(RequirementType.Any, false, feature);
2323

24-
filters.Add(new FeatureGatedAsyncActionFilter<TFilterType>(RequirementType.Any, false, feature));
24+
filters.Add(filterMetadata);
2525

2626
return filterMetadata;
2727
}
@@ -32,12 +32,14 @@ public static IFilterMetadata AddForFeature<TFilterType>(this FilterCollection f
3232
/// <typeparam name="TFilterType">The MVC filter to add and use if the feature is enabled.</typeparam>
3333
/// <param name="filters">The filter collection to add to.</param>
3434
/// <param name="features">The features that control whether the MVC filter executes.</param>
35-
/// <returns>The reference to the filter collection.</returns>
36-
public static FilterCollection AddForFeature<TFilterType>(this FilterCollection filters, params string[] features) where TFilterType : IAsyncActionFilter
35+
/// <returns>The reference to the added filter metadata.</returns>
36+
public static IFilterMetadata AddForFeature<TFilterType>(this FilterCollection filters, params string[] features) where TFilterType : IAsyncActionFilter
3737
{
38-
filters.Add(new FeatureGatedAsyncActionFilter<TFilterType>(RequirementType.Any, false, features));
38+
IFilterMetadata filterMetadata = new FeatureGatedAsyncActionFilter<TFilterType>(RequirementType.Any, false, features);
3939

40-
return filters;
40+
filters.Add(filterMetadata);
41+
42+
return filterMetadata;
4143
}
4244

4345
/// <summary>
@@ -47,12 +49,14 @@ public static FilterCollection AddForFeature<TFilterType>(this FilterCollection
4749
/// <param name="filters">The filter collection to add to.</param>
4850
/// <param name="requirementType">Specifies whether all or any of the provided features should be enabled.</param>
4951
/// <param name="features">The features that control whether the MVC filter executes.</param>
50-
/// <returns>The reference to the filter collection.</returns>
51-
public static FilterCollection AddForFeature<TFilterType>(this FilterCollection filters, RequirementType requirementType, params string[] features) where TFilterType : IAsyncActionFilter
52+
/// <returns>The reference to the added filter metadata.</returns>
53+
public static IFilterMetadata AddForFeature<TFilterType>(this FilterCollection filters, RequirementType requirementType, params string[] features) where TFilterType : IAsyncActionFilter
5254
{
53-
filters.Add(new FeatureGatedAsyncActionFilter<TFilterType>(requirementType, false, features));
55+
IFilterMetadata filterMetadata = new FeatureGatedAsyncActionFilter<TFilterType>(requirementType, false, features);
56+
57+
filters.Add(filterMetadata);
5458

55-
return filters;
59+
return filterMetadata;
5660
}
5761

5862
/// <summary>
@@ -63,12 +67,14 @@ public static FilterCollection AddForFeature<TFilterType>(this FilterCollection
6367
/// <param name="requirementType">Specifies whether all or any of the provided features should be enabled.</param>
6468
/// <param name="negate">Whether to negate the evaluation result for the provided features set.</param>
6569
/// <param name="features">The features that control whether the MVC filter executes.</param>
66-
/// <returns>The reference to the filter collection.</returns>
67-
public static FilterCollection AddForFeature<TFilterType>(this FilterCollection filters, RequirementType requirementType, bool negate, params string[] features) where TFilterType : IAsyncActionFilter
70+
/// <returns>The reference to the added filter metadata.</returns>
71+
public static IFilterMetadata AddForFeature<TFilterType>(this FilterCollection filters, RequirementType requirementType, bool negate, params string[] features) where TFilterType : IAsyncActionFilter
6872
{
69-
filters.Add(new FeatureGatedAsyncActionFilter<TFilterType>(requirementType, negate, features));
73+
IFilterMetadata filterMetadata = new FeatureGatedAsyncActionFilter<TFilterType>(requirementType, negate, features);
74+
75+
filters.Add(filterMetadata);
7076

71-
return filters;
77+
return filterMetadata;
7278
}
7379
}
7480
}

0 commit comments

Comments
 (0)