Skip to content

Commit 44be34e

Browse files
committed
Merge branch 'feature/v3' into user/jimmyca/merge/feature/v3
2 parents e3eb4da + 28982a1 commit 44be34e

File tree

84 files changed

+3539
-589
lines changed

Some content is hidden

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

84 files changed

+3539
-589
lines changed

Microsoft.FeatureManagement.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "examples\Cons
1919
EndProject
2020
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetingConsoleApp", "examples\TargetingConsoleApp\TargetingConsoleApp.csproj", "{6558C21E-CF20-4278-AA08-EB9D1DF29D66}"
2121
EndProject
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomAssignmentConsoleApp", "examples\CustomAssignmentConsoleApp\CustomAssignmentConsoleApp.csproj", "{06C10E31-4C33-4567-85DB-00056A2BB511}"
23+
EndProject
2224
Global
2325
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2426
Debug|Any CPU = Debug|Any CPU
@@ -49,6 +51,10 @@ Global
4951
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Debug|Any CPU.Build.0 = Debug|Any CPU
5052
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.ActiveCfg = Release|Any CPU
5153
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{06C10E31-4C33-4567-85DB-00056A2BB511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55+
{06C10E31-4C33-4567-85DB-00056A2BB511}.Debug|Any CPU.Build.0 = Debug|Any CPU
56+
{06C10E31-4C33-4567-85DB-00056A2BB511}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{06C10E31-4C33-4567-85DB-00056A2BB511}.Release|Any CPU.Build.0 = Release|Any CPU
5258
EndGlobalSection
5359
GlobalSection(SolutionProperties) = preSolution
5460
HideSolutionNode = FALSE
@@ -58,6 +64,7 @@ Global
5864
{FDBB27BA-C5BA-48A7-BA9B-63159943EA9F} = {8ED6FFEE-4037-49A2-9709-BC519C104A90}
5965
{E50FB931-7A42-440E-AC47-B8DFE5E15394} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
6066
{6558C21E-CF20-4278-AA08-EB9D1DF29D66} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
67+
{06C10E31-4C33-4567-85DB-00056A2BB511} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
6168
EndGlobalSection
6269
GlobalSection(ExtensibilityGlobals) = postSolution
6370
SolutionGuid = {84DA6C54-F140-4518-A1B4-E4CF42117FBD}

README.md

Lines changed: 365 additions & 107 deletions
Large diffs are not rendered by default.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"$schema":"http://json-schema.org/draft-07/schema#",
3+
"$id":"http://azconfig.io/schemas/FeatureManagement-DotNet/v1.0.0/FeatureManagement.json",
4+
"title":"Decalaration of features in the Microsoft.FeatureManagement library.",
5+
"definitions": {
6+
"FeatureFlag": {
7+
"type":"object",
8+
"properties": {
9+
"EnabledFor": {
10+
"type":"array",
11+
"items": {
12+
"type":"object",
13+
"required":[
14+
"Name"
15+
],
16+
"properties": {
17+
"Name": {
18+
"type":"string"
19+
},
20+
"Parameters": {
21+
"type":"object",
22+
"patternProperties": {
23+
"^.*$": {
24+
"anyOf":[
25+
{
26+
"type":"string"
27+
},
28+
{
29+
"type":"null"
30+
},
31+
{
32+
"type":"object"
33+
},
34+
{
35+
"type":"number"
36+
},
37+
{
38+
"type":"array"
39+
},
40+
{
41+
"type":"boolean"
42+
}
43+
]
44+
}
45+
},
46+
"additionalProperties":false
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
},
54+
"type":"object",
55+
"required":[
56+
],
57+
"properties": {
58+
"FeatureManagement": {
59+
"type":"object",
60+
"patternProperties": {
61+
"^.*$": {
62+
"anyOf":[
63+
{
64+
"$ref":"#/definitions/FeatureFlag"
65+
},
66+
{
67+
"type":"boolean"
68+
}
69+
]
70+
}
71+
},
72+
"additionalProperties":false
73+
}
74+
}
75+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"$schema":"http://json-schema.org/draft-07/schema#",
3+
"$id":"http://azconfig.io/schemas/FeatureManagement-DotNet/v2.0.0/FeatureManagement.json",
4+
"title":"Decalaration of features in the Microsoft.FeatureManagement library.",
5+
"definitions": {
6+
"FeatureFlag": {
7+
"type":"object",
8+
"properties": {
9+
"EnabledFor": {
10+
"type":"array",
11+
"items": {
12+
"type":"object",
13+
"required":[
14+
"Name"
15+
],
16+
"properties": {
17+
"Name": {
18+
"type":"string"
19+
},
20+
"Parameters": {
21+
"type":"object",
22+
"patternProperties": {
23+
"^.*$": {
24+
"anyOf":[
25+
{
26+
"type":"string"
27+
},
28+
{
29+
"type":"null"
30+
},
31+
{
32+
"type":"object"
33+
},
34+
{
35+
"type":"number"
36+
},
37+
{
38+
"type":"array"
39+
},
40+
{
41+
"type":"boolean"
42+
}
43+
]
44+
}
45+
},
46+
"additionalProperties":false
47+
}
48+
}
49+
}
50+
}
51+
}
52+
},
53+
"DynamicFeature": {
54+
"type":"object",
55+
"required": [
56+
"Assigner",
57+
"Variants"
58+
],
59+
"properties": {
60+
"Assigner": {
61+
"type":"string"
62+
},
63+
"Variants": {
64+
"type":"array",
65+
"items": {
66+
"type":"object",
67+
"required":[
68+
"Name",
69+
"ConfigurationReference"
70+
],
71+
"properties": {
72+
"Default": {
73+
"type":"boolean"
74+
},
75+
"Name": {
76+
"type":"string"
77+
},
78+
"ConfigurationReference": {
79+
"type":"string"
80+
},
81+
"AssignmentParameters": {
82+
"type":"object",
83+
"patternProperties": {
84+
"^.*$": {
85+
"anyOf":[
86+
{
87+
"type":"string"
88+
},
89+
{
90+
"type":"null"
91+
},
92+
{
93+
"type":"object"
94+
},
95+
{
96+
"type":"number"
97+
},
98+
{
99+
"type":"array"
100+
},
101+
{
102+
"type":"boolean"
103+
}
104+
]
105+
}
106+
},
107+
"additionalProperties":false
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
},
115+
"type":"object",
116+
"required":[
117+
],
118+
"properties": {
119+
"FeatureManagement": {
120+
"type":"object",
121+
"properties": {
122+
"FeatureFlags": {
123+
"type":"object",
124+
"patternProperties": {
125+
"^.*$": {
126+
"anyOf":[
127+
{
128+
"$ref":"#/definitions/FeatureFlag"
129+
},
130+
{
131+
"type":"boolean"
132+
}
133+
]
134+
}
135+
},
136+
"additionalProperties":false
137+
},
138+
"DynamicFeatures": {
139+
"type":"object",
140+
"patternProperties": {
141+
"^.*$": {
142+
"$ref":"#/definitions/DynamicFeature"
143+
}
144+
},
145+
"additionalProperties":false
146+
}
147+
}
148+
}
149+
}
150+
}

docs/schemas/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Configuration Schemas
2+
3+
This folder contains the schemas for the configuration used by the Microsoft.FeatureManagement library.
4+
5+
# 1.0.0
6+
7+
The [1.0.0 schema](./FeatureManagement.v1.0.0.json) is supported by Microsoft.FeatureManagement version 1.x - 3.x.
8+
9+
* Allows feature flags to be defined.
10+
11+
# 2.0.0
12+
13+
The [2.0.0 schema](./FeatureManagement.v2.0.0.json) is supported by Microsoft.FeatureManagement version 3.x.
14+
15+
* Allows dynamic features to be defined.
16+
* Uses a more explicit path to define feature flags.
17+
* "FeatureManagement:FeatureFlags:{flagName}" instead of "FeatureManagement:{flagName}".

examples/ConsoleApp/FeatureFilters/AccountIdFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.FeatureManagement;
77
using System;
88
using System.Collections.Generic;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace Consoto.Banking.AccountService.FeatureManagement
@@ -17,7 +18,7 @@ namespace Consoto.Banking.AccountService.FeatureManagement
1718
[FilterAlias("AccountId")]
1819
class AccountIdFilter : IContextualFeatureFilter<IAccountContext>
1920
{
20-
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext)
21+
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext, CancellationToken cancellationToken)
2122
{
2223
if (string.IsNullOrEmpty(accountContext?.AccountId))
2324
{

examples/ConsoleApp/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.FeatureManagement.FeatureFilters;
99
using System;
1010
using System.Collections.Generic;
11+
using System.Threading;
1112
using System.Threading.Tasks;
1213

1314
namespace Consoto.Banking.AccountService
@@ -58,7 +59,7 @@ public static async Task Main(string[] args)
5859
AccountId = account
5960
};
6061

61-
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext);
62+
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext, CancellationToken.None);
6263

6364
//
6465
// Output results
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<RootNamespace>Consoto.Banking.AccountService</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\Microsoft.FeatureManagement\Microsoft.FeatureManagement.csproj" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Update="appsettings.json">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
namespace Consoto.Banking.HelpDesk
5+
{
6+
class DailyDiscountOptions
7+
{
8+
public string ProductName { get; set; }
9+
10+
public int Discount { get; set; }
11+
}
12+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
//
4+
using Consoto.Banking.AccountService;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.FeatureManagement;
8+
using System;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
12+
namespace Consoto.Banking.HelpDesk
13+
{
14+
class Program
15+
{
16+
public static async Task Main(string[] args)
17+
{
18+
//
19+
// Setup configuration
20+
IConfiguration configuration = new ConfigurationBuilder()
21+
.AddJsonFile("appsettings.json", false, true)
22+
.Build();
23+
24+
//
25+
// Setup application services + feature management
26+
IServiceCollection services = new ServiceCollection();
27+
28+
services.AddSingleton(typeof(IFeatureVariantAssignerMetadata), typeof(RecurringAssigner));
29+
30+
services.AddSingleton(configuration)
31+
.AddFeatureManagement()
32+
.AddFeatureVariantAssigner<RecurringAssigner>();
33+
34+
//
35+
// Get the feature manager from application services
36+
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
37+
{
38+
IDynamicFeatureManager dynamicFeatureManager = serviceProvider.GetRequiredService<IDynamicFeatureManager>();
39+
40+
DailyDiscountOptions discountOptions = await dynamicFeatureManager
41+
.GetVariantAsync<DailyDiscountOptions>("DailyDiscount", CancellationToken.None);
42+
43+
//
44+
// Output results
45+
Console.WriteLine($"Today there is a {discountOptions.Discount}% discount on {discountOptions.ProductName}!");
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)