AwsFeatureFlags 0.1.16
dotnet add package AwsFeatureFlags --version 0.1.16
NuGet\Install-Package AwsFeatureFlags -Version 0.1.16
<PackageReference Include="AwsFeatureFlags" Version="0.1.16" />
paket add AwsFeatureFlags --version 0.1.16
#r "nuget: AwsFeatureFlags, 0.1.16"
// Install AwsFeatureFlags as a Cake Addin #addin nuget:?package=AwsFeatureFlags&version=0.1.16 // Install AwsFeatureFlags as a Cake Tool #tool nuget:?package=AwsFeatureFlags&version=0.1.16
AwsFeatureFlags
Wrapper around AWS AppConfig for Simple Feature Flags.
To use simply add:
var services = new ServiceCollection();
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
services.AddSingleton(configuration);
services.AddDefaultAWSOptions(p => p.GetService<IConfiguration>().GetAWSOptions());
services.AddFeatureFlags();
var provider = services.BuildServiceProvider();
Configuration
By default AwsFeatureFlags pulls its configuration from IConfiguration
which can be configured in many ways and come from any number of sources.
Without specifying a configuration source, AwsFeatureFlags will look for a FeatureFlags
section in the appsettings.json
file, or other configuration source.
AwsFeatureFlags can also be configured using one of the overrides of AddFeatureFlags()
, as follows:
services.AddFeatureFlags(o => myPreconfiguredOptions);
Or:
services.AddFeatureFlags(o => {
o.ApplicationIdentifier = "myApp";
o.EnvironmentIdentifier = "dev";
o.ConfigurationProfileIdentifier = "default";
});
Note that you don't have to set
RequiredMinimumPollIntervalInSeconds
as it will default to 120 seconds (2 minutes).
Or:
services.AddFeatureFlags(p => {
var myService = p.GetService<MyService>();
return myService.GetOptions();
});
In all of the above cases the AddFeatureFlags()
method takes care of everything that AwsFeatureFlags needs to work.
AWS Configuration
AwsFeatureFlags does use the AWSSDK.Extensions.NETCore.Setup
package, and as such you will need the following somewhere in your dependency tree:
services.AddDefaultAWSOptions(p => p.GetService<IConfiguration>().GetAWSOptions());
Usage
AwsFeatureFlags provides a simple interface for checking feature flags:
- Simply configure as above and the
IFeatureFlagService
will be added to your DI tree - Inject into a class you are using:
namespace: mynamespace; public class MyClass { private readonly IFeatureFlagService _featureFlags; public MyClass(IFeatureFlagService featureFlags) => _featureFlags = featureFlags; public async Task Get() { var enabled = await _featureFlags.IsEnabledAsync("my_flag"); if(!enabled) return; // do some things here } }
Methods
AwsFeatureFlags provides a single service IFeatureFlagService
which encapsulates all the functionality that this package provides.
This provides the following methods:
Signature | Return Type | Description |
---|---|---|
Get(string key) |
FeatureFlag |
Gets a single Feature Flag. |
GetAsync(string key, CancellationToken cancellationToken = default) |
Task<FeatureFlag> |
Gets a single feature flag asynchronously. |
IsEnabled(string key) |
bool |
Returns whether or not a given flag is enabled. If the flag is not found, it returns true . |
IsEnabledAsync(string key, CancellationToken cancellationToken = default) |
Task<bool> |
Returns whether or not a given flag is enabled asynchronously. If the flag is not found, it returns true . |
All() |
IEnumerable<FeatureFlag> |
Gets all known feature flags. |
AllAsync(CancellationToken cancellationToken = default) |
Task<IEnumerable<FeatureFlag>> |
Gets all know feature flags asynchronously. |
Notes
- The feature flags need to be defined, and setup as per the AWS documentation (here).
- The
key
used needs to exactly correspond to what has been created in AppConfig. - AwsFeatureFlags will not throw an exception if a flag is not found, the default behaviour is to return
true
, ornull
if not found.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- AWSSDK.AppConfigData (>= 3.7.200.65)
- AWSSDK.Extensions.NETCore.Setup (>= 3.7.7)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.