Skip to content

Commit

Permalink
Recreates examples with latest packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rossgrambo committed Oct 12, 2023
1 parent a7e5b90 commit d6720ea
Show file tree
Hide file tree
Showing 245 changed files with 158,503 additions and 8,582 deletions.
52 changes: 26 additions & 26 deletions Microsoft.FeatureManagement.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31825.309
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagDemo", "examples\FeatureFlagDemo\FeatureFlagDemo.csproj", "{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FeatureManagement", "src\Microsoft.FeatureManagement\Microsoft.FeatureManagement.csproj", "{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.FeatureManagement", "tests\Tests.FeatureManagement\Tests.FeatureManagement.csproj", "{FDBB27BA-C5BA-48A7-BA9B-63159943EA9F}"
Expand All @@ -15,24 +13,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FeatureManagement
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "examples\ConsoleApp\ConsoleApp.csproj", "{E50FB931-7A42-440E-AC47-B8DFE5E15394}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.FeatureManagement.AspNetCore", "tests\Tests.FeatureManagement.AspNetCore\Tests.FeatureManagement.AspNetCore.csproj", "{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "examples\ConsoleApp\ConsoleApp.csproj", "{7B98D293-F270-423E-A9A6-0D388E903AE9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetingConsoleApp", "examples\TargetingConsoleApp\TargetingConsoleApp.csproj", "{6558C21E-CF20-4278-AA08-EB9D1DF29D66}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorPages", "examples\RazorPages\RazorPages.csproj", "{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPages", "examples\RazorPages\RazorPages.csproj", "{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagDemo", "examples\FeatureFlagDemo\FeatureFlagDemo.csproj", "{DACAB624-4611-42E8-844C-529F93A54980}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.FeatureManagement.AspNetCore", "tests\Tests.FeatureManagement.AspNetCore\Tests.FeatureManagement.AspNetCore.csproj", "{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TargetingConsoleApp", "examples\TargetingConsoleApp\TargetingConsoleApp.csproj", "{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F}.Release|Any CPU.Build.0 = Release|Any CPU
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED1A3494-6D5B-4B27-BA9C-8BAF93E36955}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -45,33 +41,37 @@ Global
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFD3E549-2E24-490D-A7F6-F95E56A81092}.Release|Any CPU.Build.0 = Release|Any CPU
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E50FB931-7A42-440E-AC47-B8DFE5E15394}.Release|Any CPU.Build.0 = Release|Any CPU
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6558C21E-CF20-4278-AA08-EB9D1DF29D66}.Release|Any CPU.Build.0 = Release|Any CPU
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2}.Release|Any CPU.Build.0 = Release|Any CPU
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4}.Release|Any CPU.Build.0 = Release|Any CPU
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B98D293-F270-423E-A9A6-0D388E903AE9}.Release|Any CPU.Build.0 = Release|Any CPU
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3}.Release|Any CPU.Build.0 = Release|Any CPU
{DACAB624-4611-42E8-844C-529F93A54980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DACAB624-4611-42E8-844C-529F93A54980}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DACAB624-4611-42E8-844C-529F93A54980}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DACAB624-4611-42E8-844C-529F93A54980}.Release|Any CPU.Build.0 = Release|Any CPU
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E58A64A6-BE10-4D7A-AAB8-C3E2925CB32F} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{FDBB27BA-C5BA-48A7-BA9B-63159943EA9F} = {8ED6FFEE-4037-49A2-9709-BC519C104A90}
{E50FB931-7A42-440E-AC47-B8DFE5E15394} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{6558C21E-CF20-4278-AA08-EB9D1DF29D66} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{BA29A1BB-81D5-4EB1-AF37-6ECF64AF27E2} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{FC0DC3E2-5646-4AEC-A7DB-2D6167BC3BB4} = {8ED6FFEE-4037-49A2-9709-BC519C104A90}
{7B98D293-F270-423E-A9A6-0D388E903AE9} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{36DBB413-D9CA-4C56-AE5B-EAEA4C344DB3} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{DACAB624-4611-42E8-844C-529F93A54980} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
{283D3EBB-4716-4F1D-BA51-A435F7E2AB82} = {FB5C34DF-695C-4DF9-8AED-B3EA2516EA72}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {84DA6C54-F140-4518-A1B4-E4CF42117FBD}
Expand Down
11 changes: 3 additions & 8 deletions examples/ConsoleApp/AccountServiceContext.cs
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; }
}
5 changes: 3 additions & 2 deletions examples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Consoto.Banking.AccountService</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
33 changes: 13 additions & 20 deletions examples/ConsoleApp/FeatureFilters/AccountIdFilter.cs
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));
}
}
7 changes: 2 additions & 5 deletions examples/ConsoleApp/FeatureFilters/IAccountContext.cs
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; }
}
88 changes: 36 additions & 52 deletions examples/ConsoleApp/Program.cs
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.");
}
}
}
12 changes: 12 additions & 0 deletions examples/ConsoleApp2/AccountServiceContext.cs
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; }
}
}
24 changes: 24 additions & 0 deletions examples/ConsoleApp2/ConsoleApp2.csproj
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>
34 changes: 34 additions & 0 deletions examples/ConsoleApp2/FeatureFilters/AccountIdFilter.cs
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));
}
}
}
10 changes: 10 additions & 0 deletions examples/ConsoleApp2/FeatureFilters/IAccountContext.cs
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; }
}
}
Loading

0 comments on commit d6720ea

Please sign in to comment.