-
Notifications
You must be signed in to change notification settings - Fork 114
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
Recreates examples with latest packages #277
Merged
Merged
Changes from all commits
Commits
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 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
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ public Task HandleDisabledFeatures(IEnumerable<string> features, ActionExecuting | |
{ | ||
var result = new ViewResult() | ||
{ | ||
ViewName = "Views/Shared/FeatureNotEnabled.cshtml", | ||
ViewName = "Pages/Shared/FeatureNotEnabled.cshtml", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no "Pages" folder. |
||
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) | ||
}; | ||
|
||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why'd the namespace go away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ConsoleApp and other VS templates now defaults to https://aka.ms/new-console-template
Namespace automatically matches the project name. I left the namespace, "class Program", "Main" scaffolding in some of the Examples, but wanted to use the new console template in at least a few places to better match the new template. ConsoleApp makes the most sense to be minimalistic to me.