Skip to content

Commit

Permalink
chore: add FeatureManagement documentation (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpattison committed May 8, 2024
1 parent f2583d4 commit 01286c9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"bump-patch-for-minor-pre-major": true,
"versioning": "default",
"extra-files": [
"OpenFeature.Contrib.Providers.FeatureManagement.csproj"
"OpenFeature.Contrib.Providers.FeatureManagement.csproj",
"README.md"
]
},
"src/OpenFeature.Contrib.Providers.Statsig": {
Expand Down
105 changes: 105 additions & 0 deletions src/OpenFeature.Contrib.Providers.FeatureManagement/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# FeatureManagement .NET Provider
> ![NOTE]
> This requires a new feature of the FeatureManagement system, Variants. This feature is still in preview and has not been fully released.
The FeatureManagement Provider allows you to use the FeatureManagement system as an OpenFeature Provider.

## .NET SDK Usage

### Install dependencies
<!--- {x-release-please-start-version} -->

#### .NET Cli

```shell
dotnet add package OpenFeature.Contrib.Provider.FeatureManagement --version 0.0.1-preview
```

#### Package Manager

```shell
NuGet\Install-Package OpenFeature.Contrib.Provider.FeatureManagement -Version 0.0.1-preview
```

#### Package Reference

```xml
<PackageReference Include="OpenFeature.Contrib.Provider.FeatureManagement" Version="0.0.1-preview" />
```

#### Paket CLI
```shell
paket add OpenFeature.Contrib.Provider.FeatureManagement --version 0.0.1-preview
```

#### Cake

```shell
// Install OpenFeature.Contrib.Provider.FeatureManagement as a Cake Addin
#addin nuget:?package=OpenFeature.Contrib.Provider.FeatureManagement&version=0.0.1-preview&prerelease

// Install OpenFeature.Contrib.Provider.FeatureManagement as a Cake Tool
#tool nuget:?package=OpenFeature.Contrib.Provider.FeatureManagement&version=0.0.1-preview&prerelease
```
<!--- {x-release-please-end} -->

### Using the FeatureManagement Provider with the OpenFeature SDK

FeatureManagement is built on top of .NETs Configuration system, so you must provide the loaded Configuration.
Since Configuration is passed in any valid Configuration source can be used.
For simplicity, we'll stick with a json file for all examples.

```csharp
namespace OpenFeatureTestApp
{
class Program
{
static void Main(string[] args)
{
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("featureFlags.json");

IConfiguration configuration = configurationBuilder.Build();

var featureManagementProvider = new FeatureManagementProvider(configuration);
OpenFeature.Api.Instance.SetProvider(featureManagementProvider);

var client = OpenFeature.Api.Instance.GetClient();

var val = await client.GetBooleanValue("myBoolFlag", false, null);

System.Console.WriteLine(val.ToString());
}
}
}
```

A simple example configuration would look like this.

```json
{
"FeatureManagement": {
"myBoolFlag": {
"Allocation": {
"DefaultWhenEnabled": "FlagEnabled",
"DefaultWhenDisabled": "FlagDisabled"
},
"Variants": [
{
"Name": "FlagEnabled",
"ConfigurationValue": true
},
{
"Name": "FlagDisabled",
"ConfigurationValue": false
}
],
"EnabledFor": [
{
"Name": "AlwaysOn"
}
]
}
}
}
```

0 comments on commit 01286c9

Please sign in to comment.