-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathProgram.cs
55 lines (46 loc) · 1.48 KB
/
Program.cs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
//
// Setup configuration
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
//
// Setup application services + feature management
IServiceCollection services = new ServiceCollection();
services.AddSingleton(configuration)
.AddFeatureManagement()
.AddFeatureFilter<AccountIdFilter>();
//
// Get the feature manager from application services
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
var accounts = new List<string>()
{
"abc",
"adef",
"abcdefghijklmnopqrstuvwxyz"
};
//
// Mimic work items in a task-driven console application
foreach (var account in accounts)
{
const string FeatureName = "Beta";
//
// Check if feature enabled
//
var accountServiceContext = new AccountServiceContext
{
AccountId = account
};
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext);
//
// Output results
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account.");
}
}