-
Notifications
You must be signed in to change notification settings - Fork 119
Add support for dynamic features. #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jimmyca15
merged 10 commits into
microsoft:feature/v3
from
jimmyca15:user/jimmyca/fVariants
Nov 17, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99a3bde
Add support for feature variants.
jimmyca15 57b06b3
Renaming and assorted fixes.
jimmyca15 b8d1353
Remove unnecessary field.
jimmyca15 6ea29fd
* Added additional argument validation.
jimmyca15 2f52403
Since filter aliases are case insensitive, update filter cache to ref…
jimmyca15 356077d
* Fixed issue with filter + assigner suffix references.
jimmyca15 5ed4021
Share suffix matching logic. Corrected variable name.
jimmyca15 0044eeb
Removed unnecessary helper methods.
jimmyca15 d064c97
Clarify filter selection logic in feature evaluation and add checks f…
jimmyca15 10cd771
Updated argument validation messages.
jimmyca15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
examples/CustomAssignmentConsoleApp/CustomAssignmentConsoleApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net5.0</TargetFramework> | ||
| <RootNamespace>Consoto.Banking.AccountService</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Microsoft.FeatureManagement\Microsoft.FeatureManagement.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="appsettings.json"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
12 changes: 12 additions & 0 deletions
12
examples/CustomAssignmentConsoleApp/DailyDiscountOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| namespace Consoto.Banking.HelpDesk | ||
| { | ||
| class DailyDiscountOptions | ||
| { | ||
| public string ProductName { get; set; } | ||
|
|
||
| public int Discount { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using Consoto.Banking.AccountService; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.FeatureManagement; | ||
| using System; | ||
| using System.Threading; | ||
| 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", false, true) | ||
| .Build(); | ||
|
|
||
| // | ||
| // Setup application services + feature management | ||
| IServiceCollection services = new ServiceCollection(); | ||
|
|
||
| services.AddSingleton(typeof(IFeatureVariantAssignerMetadata), typeof(RecurringAssigner)); | ||
|
|
||
| services.AddSingleton(configuration) | ||
| .AddFeatureManagement() | ||
| .AddFeatureVariantAssigner<RecurringAssigner>(); | ||
|
|
||
| // | ||
| // Get the feature manager from application services | ||
| using (ServiceProvider serviceProvider = services.BuildServiceProvider()) | ||
| { | ||
| IFeatureVariantManager variantManager = serviceProvider.GetRequiredService<IFeatureVariantManager>(); | ||
|
|
||
| DailyDiscountOptions discountOptions = await variantManager | ||
| .GetVariantAsync<DailyDiscountOptions>("DailyDiscount", CancellationToken.None); | ||
|
|
||
| // | ||
| // Output results | ||
| Console.WriteLine($"Today there is a {discountOptions.Discount}% discount on {discountOptions.ProductName}!"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.FeatureManagement; | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Consoto.Banking.AccountService | ||
| { | ||
| [AssignerAlias("Recurring")] | ||
| class RecurringAssigner : IFeatureVariantAssigner | ||
| { | ||
| public ValueTask<FeatureVariant> AssignVariantAsync(FeatureVariantAssignmentContext variantAssignmentContext, CancellationToken _) | ||
| { | ||
| FeatureDefinition featureDefinition = variantAssignmentContext.FeatureDefinition; | ||
|
|
||
| FeatureVariant chosenVariant = null; | ||
|
|
||
| string currentDay = DateTimeOffset.UtcNow.DayOfWeek.ToString(); | ||
|
|
||
| foreach (var variant in featureDefinition.Variants) | ||
| { | ||
| RecurringAssignmentParameters p = variant.AssignmentParameters.Get<RecurringAssignmentParameters>() ?? | ||
| new RecurringAssignmentParameters(); | ||
|
|
||
| if (p.Days != null && | ||
| p.Days.Any(d => d.Equals(currentDay, StringComparison.OrdinalIgnoreCase))) | ||
| { | ||
| chosenVariant = variant; | ||
|
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
| return new ValueTask<FeatureVariant>(chosenVariant); | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
examples/CustomAssignmentConsoleApp/RecurringAssignmentParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Consoto.Banking.AccountService | ||
| { | ||
| class RecurringAssignmentParameters | ||
| { | ||
| public List<string> Days { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "FeatureManagement": { | ||
| "DailyDiscount": { | ||
| "Assigner": "Recurring", | ||
| "Variants": [ | ||
| { | ||
| "Default": true, | ||
| "Name": "Default", | ||
| "ConfigurationReference": "DailyDiscount:Default" | ||
| }, | ||
| { | ||
| "Name": "Special", | ||
| "ConfigurationReference": "DailyDiscount:Special", | ||
| "AssignmentParameters": { | ||
| "Days": [ | ||
| "Tuesday" | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "DailyDiscount": { | ||
| "Default": { | ||
| "Discount": 20, | ||
| "ProductName": "Bananas" | ||
| }, | ||
| "Special": { | ||
| "Discount": 30, | ||
| "ProductName": "Fish" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| namespace FeatureFlagDemo | ||
| { | ||
| public class DiscountBannerOptions | ||
| { | ||
| public int Size { get; set; } | ||
|
|
||
| public string Color { get; set; } | ||
|
|
||
| public string Background { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| namespace Consoto.Banking.HelpDesk | ||
| { | ||
| class CartOptions | ||
| { | ||
| public int Size { get; set; } | ||
|
|
||
| public string Color { get; set; } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.