-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recreates examples with latest packages
- Loading branch information
1 parent
a7e5b90
commit d6720ea
Showing
245 changed files
with
158,503 additions
and
8,582 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
using Consoto.Banking.AccountService.FeatureFilters; | ||
|
||
namespace Consoto.Banking.AccountService | ||
class AccountServiceContext : IAccountContext | ||
{ | ||
class AccountServiceContext : IAccountContext | ||
{ | ||
public string AccountId { get; set; } | ||
} | ||
} | ||
public string AccountId { get; set; } | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,34 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
using Consoto.Banking.AccountService.FeatureFilters; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.FeatureManagement; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Consoto.Banking.AccountService.FeatureManagement | ||
/// <summary> | ||
/// 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. | ||
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation. | ||
/// </summary> | ||
[FilterAlias("AccountId")] | ||
class AccountIdFilter : IContextualFeatureFilter<IAccountContext> | ||
{ | ||
/// <summary> | ||
/// 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. | ||
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation. | ||
/// </summary> | ||
[FilterAlias("AccountId")] | ||
class AccountIdFilter : IContextualFeatureFilter<IAccountContext> | ||
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext) | ||
{ | ||
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext) | ||
if (string.IsNullOrEmpty(accountContext?.AccountId)) | ||
{ | ||
if (string.IsNullOrEmpty(accountContext?.AccountId)) | ||
{ | ||
throw new ArgumentNullException(nameof(accountContext)); | ||
} | ||
throw new ArgumentNullException(nameof(accountContext)); | ||
} | ||
|
||
var allowedAccounts = new List<string>(); | ||
var allowedAccounts = new List<string>(); | ||
|
||
featureEvaluationContext.Parameters.Bind("AllowedAccounts", allowedAccounts); | ||
featureEvaluationContext.Parameters.Bind("AllowedAccounts", allowedAccounts); | ||
|
||
return Task.FromResult(allowedAccounts.Contains(accountContext.AccountId)); | ||
} | ||
return Task.FromResult(allowedAccounts.Contains(accountContext.AccountId)); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
namespace Consoto.Banking.AccountService.FeatureFilters | ||
public interface IAccountContext | ||
{ | ||
public interface IAccountContext | ||
{ | ||
string AccountId { get; } | ||
} | ||
string AccountId { get; } | ||
} |
This file contains 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 |
---|---|---|
@@ -1,70 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
using Consoto.Banking.AccountService.FeatureManagement; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.FeatureManagement; | ||
using Microsoft.FeatureManagement.FeatureFilters; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Consoto.Banking.AccountService | ||
{ | ||
class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
// | ||
// Setup configuration | ||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
// | ||
// Setup configuration | ||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
|
||
// | ||
// Setup application services + feature management | ||
IServiceCollection services = new ServiceCollection(); | ||
// | ||
// Setup application services + feature management | ||
IServiceCollection services = new ServiceCollection(); | ||
|
||
services.AddSingleton(configuration) | ||
.AddFeatureManagement() | ||
.AddFeatureFilter<PercentageFilter>() | ||
.AddFeatureFilter<AccountIdFilter>(); | ||
services.AddSingleton(configuration) | ||
.AddFeatureManagement() | ||
.AddFeatureFilter<PercentageFilter>() | ||
.AddFeatureFilter<AccountIdFilter>(); | ||
|
||
// | ||
// Get the feature manager from application services | ||
using (ServiceProvider serviceProvider = services.BuildServiceProvider()) | ||
{ | ||
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>(); | ||
// | ||
// Get the feature manager from application services | ||
using (ServiceProvider serviceProvider = services.BuildServiceProvider()) | ||
{ | ||
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>(); | ||
|
||
var accounts = new List<string>() | ||
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"; | ||
// | ||
// 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 | ||
}; | ||
// | ||
// Check if feature enabled | ||
// | ||
var accountServiceContext = new AccountServiceContext | ||
{ | ||
AccountId = account | ||
}; | ||
|
||
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext); | ||
bool enabled = await featureManager.IsEnabledAsync(FeatureName, accountServiceContext); | ||
|
||
// | ||
// Output results | ||
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account."); | ||
} | ||
} | ||
} | ||
// | ||
// Output results | ||
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account."); | ||
} | ||
} | ||
} |
This file contains 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 Consoto.Banking.AccountService.FeatureFilters; | ||
|
||
namespace Consoto.Banking.AccountService | ||
{ | ||
class AccountServiceContext : IAccountContext | ||
{ | ||
public string AccountId { get; set; } | ||
} | ||
} |
This file contains 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>net6.0</TargetFramework> | ||
<RootNamespace>Consoto.Banking.AccountService</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.FeatureManagement\Microsoft.FeatureManagement.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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,34 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
using Consoto.Banking.AccountService.FeatureFilters; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.FeatureManagement; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Consoto.Banking.AccountService.FeatureManagement | ||
{ | ||
/// <summary> | ||
/// 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. | ||
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation. | ||
/// </summary> | ||
[FilterAlias("AccountId")] | ||
class AccountIdFilter : IContextualFeatureFilter<IAccountContext> | ||
{ | ||
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext featureEvaluationContext, IAccountContext accountContext) | ||
{ | ||
if (string.IsNullOrEmpty(accountContext?.AccountId)) | ||
{ | ||
throw new ArgumentNullException(nameof(accountContext)); | ||
} | ||
|
||
var allowedAccounts = new List<string>(); | ||
|
||
featureEvaluationContext.Parameters.Bind("AllowedAccounts", allowedAccounts); | ||
|
||
return Task.FromResult(allowedAccounts.Contains(accountContext.AccountId)); | ||
} | ||
} | ||
} |
This file contains 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,10 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
namespace Consoto.Banking.AccountService.FeatureFilters | ||
{ | ||
public interface IAccountContext | ||
{ | ||
string AccountId { get; } | ||
} | ||
} |
Oops, something went wrong.