Skip to content

Commit f189d9f

Browse files
authored
Recreates examples with latest packages (#277)
1 parent 96819bb commit f189d9f

File tree

164 files changed

+134007
-9664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+134007
-9664
lines changed

Microsoft.FeatureManagement.sln

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31825.309
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagDemo", "examples\FeatureFlagDemo\FeatureFlagDemo.csproj", "{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}"
7-
EndProject
86
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FeatureManagement", "src\Microsoft.FeatureManagement\Microsoft.FeatureManagement.csproj", "{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}"
97
EndProject
108
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.FeatureManagement", "tests\Tests.FeatureManagement\Tests.FeatureManagement.csproj", "{FDBB27BA-C5BA-48A7-BA9B-63159943EA9F}"
@@ -15,24 +13,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FeatureManagement
1513
EndProject
1614
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}"
1715
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "examples\ConsoleApp\ConsoleApp.csproj", "{E50FB931-7A42-440E-AC47-B8DFE5E15394}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.FeatureManagement.AspNetCore", "tests\Tests.FeatureManagement.AspNetCore\Tests.FeatureManagement.AspNetCore.csproj", "{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "examples\ConsoleApp\ConsoleApp.csproj", "{7B98D293-F270-423E-A9A6-0D388E903AE9}"
1919
EndProject
20-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetingConsoleApp", "examples\TargetingConsoleApp\TargetingConsoleApp.csproj", "{6558C21E-CF20-4278-AA08-EB9D1DF29D66}"
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorPages", "examples\RazorPages\RazorPages.csproj", "{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}"
2121
EndProject
22-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPages", "examples\RazorPages\RazorPages.csproj", "{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}"
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagDemo", "examples\FeatureFlagDemo\FeatureFlagDemo.csproj", "{DACAB624-4611-42E8-844C-529F93A54980}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.FeatureManagement.AspNetCore", "tests\Tests.FeatureManagement.AspNetCore\Tests.FeatureManagement.AspNetCore.csproj", "{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}"
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetingConsoleApp", "examples\TargetingConsoleApp\TargetingConsoleApp.csproj", "{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}"
2525
EndProject
2626
Global
2727
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2828
Debug|Any CPU = Debug|Any CPU
2929
Release|Any CPU = Release|Any CPU
3030
EndGlobalSection
3131
GlobalSection(ProjectConfigurationPlatforms) = postSolution
32-
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Release|Any CPU.Build.0 = Release|Any CPU
3632
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3733
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Debug|Any CPU.Build.0 = Debug|Any CPU
3834
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -45,33 +41,37 @@ Global
4541
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Debug|Any CPU.Build.0 = Debug|Any CPU
4642
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Release|Any CPU.ActiveCfg = Release|Any CPU
4743
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49-
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Debug|Any CPU.Build.0 = Debug|Any CPU
50-
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Release|Any CPU.ActiveCfg = Release|Any CPU
51-
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Release|Any CPU.Build.0 = Release|Any CPU
52-
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53-
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Debug|Any CPU.Build.0 = Debug|Any CPU
54-
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.ActiveCfg = Release|Any CPU
55-
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.Build.0 = Release|Any CPU
56-
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57-
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
58-
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
59-
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Release|Any CPU.Build.0 = Release|Any CPU
6044
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6145
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
6246
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
6347
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Release|Any CPU.Build.0 = Release|Any CPU
52+
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
55+
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{DACAB624-4611-42E8-844C-529F93A54980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{DACAB624-4611-42E8-844C-529F93A54980}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{DACAB624-4611-42E8-844C-529F93A54980}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{DACAB624-4611-42E8-844C-529F93A54980}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Release|Any CPU.ActiveCfg = Release|Any CPU
63+
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Release|Any CPU.Build.0 = Release|Any CPU
6464
EndGlobalSection
6565
GlobalSection(SolutionProperties) = preSolution
6666
HideSolutionNode = FALSE
6767
EndGlobalSection
6868
GlobalSection(NestedProjects) = preSolution
69-
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
7069
{FDBB27BA-C5BA-48A7-BA9B-63159943EA9F} = {8ED6FFEE-4037-49A2-9709-BC519C104A90}
71-
{E50FB931-7A42-440E-AC47-B8DFE5E15394} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
72-
{6558C21E-CF20-4278-AA08-EB9D1DF29D66} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
73-
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
7470
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4} = {8ED6FFEE-4037-49A2-9709-BC519C104A90}
71+
{7B98D293-F270-423E-A9A6-0D388E903AE9} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
72+
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
73+
{DACAB624-4611-42E8-844C-529F93A54980} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
74+
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
7575
EndGlobalSection
7676
GlobalSection(ExtensibilityGlobals) = postSolution
7777
SolutionGuid = {84DA6C54-F140-4518-A1B4-E4CF42117FBD}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
//
4-
using Consoto.Banking.AccountService.FeatureFilters;
5-
6-
namespace Consoto.Banking.AccountService
4+
class AccountServiceContext : IAccountContext
75
{
8-
class AccountServiceContext : IAccountContext
9-
{
10-
public string AccountId { get; set; }
11-
}
12-
}
6+
public string AccountId { get; set; }
7+
}

examples/ConsoleApp/ConsoleApp.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6-
<RootNamespace>Consoto.Banking.AccountService</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
78
</PropertyGroup>
89

910
<ItemGroup>
Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
//
4-
using Consoto.Banking.AccountService.FeatureFilters;
54
using Microsoft.Extensions.Configuration;
65
using Microsoft.FeatureManagement;
7-
using System;
8-
using System.Collections.Generic;
9-
using System.Threading.Tasks;
106

11-
namespace Consoto.Banking.AccountService.FeatureManagement
7+
/// <summary>
8+
/// A filter that uses the feature management context to ensure that the current task has the notion of an account id, and that the account id is allowed.
9+
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation.
10+
/// </summary>
11+
[FilterAlias("AccountId")]
12+
class AccountIdFilter : IContextualFeatureFilter<IAccountContext>
1213
{
13-
/// <summary>
14-
/// A filter that uses the feature management context to ensure that the current task has the notion of an account id, and that the account id is allowed.
15-
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation.
16-
/// </summary>
17-
[FilterAlias("AccountId")]
18-
class AccountIdFilter : IContextualFeatureFilter<IAccountContext>
14+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext)
1915
{
20-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext)
16+
if (string.IsNullOrEmpty(accountContext?.AccountId))
2117
{
22-
if (string.IsNullOrEmpty(accountContext?.AccountId))
23-
{
24-
throw new ArgumentNullException(nameof(accountContext));
25-
}
18+
throw new ArgumentNullException(nameof(accountContext));
19+
}
2620

27-
var allowedAccounts = new List<string>();
21+
var allowedAccounts = new List<string>();
2822

29-
featureEvaluationContext.Parameters.Bind("AllowedAccounts", allowedAccounts);
23+
featureEvaluationContext.Parameters.Bind("AllowedAccounts", allowedAccounts);
3024

31-
return Task.FromResult(allowedAccounts.Contains(accountContext.AccountId));
32-
}
25+
return Task.FromResult(allowedAccounts.Contains(accountContext.AccountId));
3326
}
3427
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
//
4-
namespace Consoto.Banking.AccountService.FeatureFilters
4+
public interface IAccountContext
55
{
6-
public interface IAccountContext
7-
{
8-
string AccountId { get; }
9-
}
6+
string AccountId { get; }
107
}

examples/ConsoleApp/Program.cs

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,54 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// Licensed under the MIT license.
3-
//
4-
using Consoto.Banking.AccountService.FeatureManagement;
5-
using Microsoft.Extensions.Configuration;
1+
using Microsoft.Extensions.Configuration;
62
using Microsoft.Extensions.DependencyInjection;
73
using Microsoft.FeatureManagement;
84
using Microsoft.FeatureManagement.FeatureFilters;
9-
using System;
10-
using System.Collections.Generic;
11-
using System.Threading.Tasks;
125

13-
namespace Consoto.Banking.AccountService
14-
{
15-
class Program
16-
{
17-
public static async Task Main(string[] args)
18-
{
19-
//
20-
// Setup configuration
21-
IConfiguration configuration = new ConfigurationBuilder()
22-
.AddJsonFile("appsettings.json")
23-
.Build();
6+
//
7+
// Setup configuration
8+
IConfiguration configuration = new ConfigurationBuilder()
9+
.AddJsonFile("appsettings.json")
10+
.Build();
2411

25-
//
26-
// Setup application services + feature management
27-
IServiceCollection services = new ServiceCollection();
12+
//
13+
// Setup application services + feature management
14+
IServiceCollection services = new ServiceCollection();
2815

29-
services.AddSingleton(configuration)
30-
.AddFeatureManagement()
31-
.AddFeatureFilter<PercentageFilter>()
32-
.AddFeatureFilter<AccountIdFilter>();
16+
services.AddSingleton(configuration)
17+
.AddFeatureManagement()
18+
.AddFeatureFilter<PercentageFilter>()
19+
.AddFeatureFilter<AccountIdFilter>();
3320

34-
//
35-
// Get the feature manager from application services
36-
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
37-
{
38-
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
21+
//
22+
// Get the feature manager from application services
23+
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
24+
{
25+
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
3926

40-
var accounts = new List<string>()
27+
var accounts = new List<string>()
4128
{
4229
"abc",
4330
"adef",
4431
"abcdefghijklmnopqrstuvwxyz"
4532
};
4633

47-
//
48-
// Mimic work items in a task-driven console application
49-
foreach (var account in accounts)
50-
{
51-
const string FeatureName = "Beta";
34+
//
35+
// Mimic work items in a task-driven console application
36+
foreach (var account in accounts)
37+
{
38+
const string FeatureName = "Beta";
5239

53-
//
54-
// Check if feature enabled
55-
//
56-
var accountServiceContext = new AccountServiceContext
57-
{
58-
AccountId = account
59-
};
40+
//
41+
// Check if feature enabled
42+
//
43+
var accountServiceContext = new AccountServiceContext
44+
{
45+
AccountId = account
46+
};
6047

61-
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext);
48+
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext);
6249

63-
//
64-
// Output results
65-
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account.");
66-
}
67-
}
68-
}
50+
//
51+
// Output results
52+
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account.");
6953
}
70-
}
54+
}

examples/FeatureFlagDemo/FeatureFlagDemo.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
57
</PropertyGroup>
68

79
<ItemGroup>
@@ -13,8 +15,15 @@
1315
</ItemGroup>
1416

1517
<ItemGroup>
18+
<Content Update="appsettings.Development.json">
19+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
21+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
22+
</Content>
1623
<Content Update="appsettings.json">
1724
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
26+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1827
</Content>
1928
<Content Update="Views\Beta\Index.cshtml">
2029
<Pack>$(IncludeRazorContentInPack)</Pack>

examples/FeatureFlagDemo/FeatureNotEnabledDisabledHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public Task HandleDisabledFeatures(IEnumerable<string> features, ActionExecuting
1717
{
1818
var result = new ViewResult()
1919
{
20-
ViewName = "Views/Shared/FeatureNotEnabled.cshtml",
20+
ViewName = "Pages/Shared/FeatureNotEnabled.cshtml",
2121
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
2222
};
2323

examples/FeatureFlagDemo/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Licensed under the MIT license.
33
//
44
using Microsoft.AspNetCore;
5-
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.Extensions.Configuration;
75
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
86

97
namespace FeatureFlagDemo

examples/FeatureFlagDemo/Startup.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
using FeatureFlagDemo.Authentication;
55
using FeatureFlagDemo.FeatureManagement;
66
using FeatureFlagDemo.FeatureManagement.FeatureFilters;
7-
using Microsoft.AspNetCore.Builder;
8-
using Microsoft.AspNetCore.Hosting;
9-
using Microsoft.AspNetCore.Http;
107
using Microsoft.AspNetCore.Mvc;
11-
using Microsoft.Extensions.Configuration;
12-
using Microsoft.Extensions.DependencyInjection;
138
using Microsoft.Extensions.DependencyInjection.Extensions;
14-
using Microsoft.Extensions.Hosting;
159
using Microsoft.FeatureManagement;
1610
using Microsoft.FeatureManagement.FeatureFilters;
1711

@@ -65,7 +59,7 @@ public void ConfigureServices(IServiceCollection services)
6559
{
6660
o.Filters.AddForFeature<ThirdPartyActionFilter>(nameof(MyFeatureFlags.EnhancedPipeline));
6761

68-
}).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
62+
});
6963
}
7064

7165
public void Configure(IApplicationBuilder app, IHostEnvironment env)

0 commit comments

Comments
 (0)