-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (41 loc) · 1.41 KB
/
Program.cs
File metadata and controls
50 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
using TargetingConsoleApp.Identity;
//
// Setup configuration
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var featureManager = new FeatureManager(new ConfigurationFeatureDefinitionProvider(configuration))
{
FeatureFilters = new List<IFeatureFilterMetadata> { new ContextualTargetingFilter() }
};
var userRepository = new InMemoryUserRepository();
//
// We'll simulate a task to run on behalf of each known user
// To do this we enumerate all the users in our user repository
IEnumerable<string> userIds = InMemoryUserRepository.Users.Select(u => u.Id);
//
// Mimic work items in a task-driven console application
foreach (string userId in userIds)
{
const string FeatureName = "Beta";
//
// Get user
User user = await userRepository.GetUser(userId);
//
// Check if feature enabled
var targetingContext = new TargetingContext
{
UserId = user.Id,
Groups = user.Groups
};
bool enabled = await featureManager.IsEnabledAsync(FeatureName, targetingContext);
//
// Output results
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the user '{userId}'.");
}