forked from microsoft/FeatureManagement-Dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (63 loc) · 2.57 KB
/
Copy pathProgram.cs
File metadata and controls
74 lines (63 loc) · 2.57 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Consoto.Banking.AccountService.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Consoto.Banking.HelpDesk
{
class Program
{
public static async Task Main(string[] args)
{
//
// Setup configuration
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
//
// Setup application services + feature management
IServiceCollection services = new ServiceCollection();
services.AddSingleton(configuration)
.AddFeatureManagement()
.AddFeatureFilter<ContextualTargetingFilter>();
IUserRepository userRepository = new InMemoryUserRepository();
//
// Get the feature manager from application services
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
//
// 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
TargetingContext 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}'.");
}
}
}
}
}