Skip to content

Commit

Permalink
register built-in filter first & target on main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanliang-ms committed Oct 19, 2023
1 parent ab6d10f commit 089b4ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Microsoft.FeatureManagement/EmptyTargetingContextAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.FeatureManagement.FeatureFilters;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Microsoft.FeatureManagement
{
internal class EmptyTargetingContextAccessor : ITargetingContextAccessor
{
public ValueTask<TargetingContext> GetContextAsync()
{
TargetingContext targetingContext = new TargetingContext
{
UserId = "",
Groups = new List<string>()
};

return new ValueTask<TargetingContext>(targetingContext);
}
}
}
13 changes: 12 additions & 1 deletion src/Microsoft.FeatureManagement/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.FeatureManagement.FeatureFilters;
using System;

namespace Microsoft.FeatureManagement
Expand Down Expand Up @@ -33,7 +34,17 @@ public static IFeatureManagementBuilder AddFeatureManagement(this IServiceCollec

services.AddScoped<IFeatureManagerSnapshot, FeatureManagerSnapshot>();

return new FeatureManagementBuilder(services);
services.TryAddSingleton<ITargetingContextAccessor, EmptyTargetingContextAccessor>();

var builder = new FeatureManagementBuilder(services);

builder.AddFeatureFilter<PercentageFilter>();

builder.AddFeatureFilter<TimeWindowFilter>();

builder.AddFeatureFilter<TargetingFilter>();

return builder;
}

/// <summary>
Expand Down

0 comments on commit 089b4ce

Please sign in to comment.