-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding OpenFeature provider for Schematic
Signed-off-by: Ben Papillon <[email protected]>
- Loading branch information
Showing
9 changed files
with
606 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
src/OpenFeature.Contrib.Providers.Schematic/OpenFeature.Contrib.Providers.Schematic.csproj
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>OpenFeature.Contrib.Providers.Schematic</PackageId> | ||
<VersionNumber>0.1.0</VersionNumber> <!--x-release-please-version --> | ||
<VersionPrefix>$(VersionNumber)</VersionPrefix> | ||
<AssemblyVersion>$(VersionNumber)</AssemblyVersion> | ||
<FileVersion>$(VersionNumber)</FileVersion> | ||
<Description>Schematic provider for .NET</Description> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<Authors>Benjamin Papillon</Authors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<!-- make the internal methods visble to our test project --> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>$(MSBuildProjectName).Test</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SchematicHQ.Client" Version="1.0.6" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="README.md" Pack="true" PackagePath="\"/> | ||
</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,124 @@ | ||
# Schematic .NET Provider | ||
|
||
The Schematic provider allows you to connect to your Schematic instance through the OpenFeature SDK | ||
|
||
# .Net SDK usage | ||
|
||
## Requirements | ||
|
||
- open-feature/dotnet-sdk v1.5.0 > v2.0.0 | ||
|
||
## Install dependencies | ||
|
||
The first things we will do is install the **Open Feature SDK** and the **Schematic OpenFeature provider**. | ||
|
||
### .NET Cli | ||
```shell | ||
dotnet add package OpenFeature.Contrib.Providers.Schematic | ||
``` | ||
### Package Manager | ||
|
||
```shell | ||
NuGet\Install-Package OpenFeature.Contrib.Providers.Schematic | ||
``` | ||
### Package Reference | ||
|
||
```xml | ||
<PackageReference Include="OpenFeature.Contrib.Providers.Schematic" /> | ||
``` | ||
### Paket cli | ||
|
||
```shell | ||
paket add OpenFeature.Contrib.Providers.Schematic | ||
``` | ||
|
||
### Cake | ||
|
||
```shell | ||
// Install OpenFeature.Contrib.Providers.Schematic as a Cake Addin | ||
#addin nuget:?package=OpenFeature.Contrib.Providers.Schematic | ||
|
||
// Install OpenFeature.Contrib.Providers.Schematic as a Cake Tool | ||
#tool nuget:?package=OpenFeature.Contrib.Providers.Schematic | ||
``` | ||
|
||
## Using the Schematic Provider with the OpenFeature SDK | ||
|
||
To use Schematic as an OpenFeature provider, define your provider and Schematic settings. | ||
|
||
```csharp | ||
using OpenFeature; | ||
using OpenFeature.Contrib.Providers.Schematic; | ||
using System; | ||
|
||
var schematicProvider = new SchematicFeatureProvider("your-api-key"); | ||
|
||
// Set the schematicProvider as the provider for the OpenFeature SDK | ||
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider); | ||
|
||
// Get an OpenFeature client | ||
var client = OpenFeature.Api.Instance.GetClient("my-app"); | ||
|
||
// Set company and/or user context | ||
var context = EvaluationContext.Builder() | ||
.Set("company", new Dictionary<string, string> { | ||
{ "id", "your-company-id" }, | ||
}) | ||
.Set("user", new Dictionary<string, string> { | ||
{ "id", "your-user-id" }, | ||
}) | ||
.Build(); | ||
|
||
// Evaluate a flag | ||
var val = await client.GetBooleanValueAsync("your-flag-key", false, context); | ||
|
||
// Print the value of the 'your-flag-key' feature flag | ||
Console.WriteLine(val); | ||
``` | ||
|
||
You can also provide additional configuration options to the provider to manage caching behavior, offline mode, and other capabilities: | ||
|
||
```csharp | ||
using OpenFeature; | ||
using OpenFeature.Contrib.Providers.Schematic; | ||
using SchematicHQ.Client; | ||
using System; | ||
|
||
var options = new ClientOptions | ||
{ | ||
Offline = true, // Run in offline mode | ||
FlagDefaults = new Dictionary<string, bool> // Default values for offline mode | ||
{ | ||
{ "some-flag-key", true } | ||
}, | ||
Logger = new ConsoleLogger(), // Optional custom logger | ||
CacheProviders = new List<ICacheProvider<bool?>> // Optional cache configuration | ||
{ | ||
new LocalCache<bool?>(1000, TimeSpan.FromSeconds(30)) | ||
} | ||
}; | ||
|
||
var schematicProvider = new SchematicFeatureProvider("your-api-key", options); | ||
|
||
// Set the schematicProvider as the provider for the OpenFeature SDK | ||
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider); | ||
|
||
// Get an OpenFeature client | ||
var client = OpenFeature.Api.Instance.GetClient("my-app"); | ||
|
||
// Set company and/or user context | ||
var context = EvaluationContext.Builder() | ||
.Set("company", new Dictionary<string, string> { | ||
{ "id", "your-company-id" }, | ||
}) | ||
.Set("user", new Dictionary<string, string> { | ||
{ "id", "your-user-id" }, | ||
}) | ||
.Build(); | ||
|
||
// Evaluate a flag | ||
var val = await client.GetBooleanValueAsync("your-flag-key", false, context); | ||
|
||
// Print the value of the 'your-flag-key' feature flag | ||
Console.WriteLine(val); | ||
``` |
Oops, something went wrong.