Skip to content

Commit 67d2f76

Browse files
committed
feat: Adding OpenFeature provider for Schematic
Signed-off-by: Ben Papillon <[email protected]>
1 parent 431ca45 commit 67d2f76

9 files changed

+607
-0
lines changed

DotnetSdkContrib.sln

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Provide
4949
EndProject
5050
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.EnvVar.Test", "test\OpenFeature.Contrib.Providers.EnvVar.Test\OpenFeature.Contrib.Providers.EnvVar.Test.csproj", "{282AD5C5-099A-403D-B415-29AA88A701EC}"
5151
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Schematic", "src\OpenFeature.Contrib.Providers.Schematic\OpenFeature.Contrib.Providers.Schematic.csproj", "{CF1AB517-1D51-455F-80C0-56B4856E6A6B}"
53+
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Schematic.Test", "test\OpenFeature.Contrib.Providers.Schematic.Test\OpenFeature.Contrib.Providers.Schematic.Test.csproj", "{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}"
55+
EndProject
5256
Global
5357
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5458
Debug|Any CPU = Debug|Any CPU
@@ -139,6 +143,14 @@ Global
139143
{282AD5C5-099A-403D-B415-29AA88A701EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
140144
{282AD5C5-099A-403D-B415-29AA88A701EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
141145
{282AD5C5-099A-403D-B415-29AA88A701EC}.Release|Any CPU.Build.0 = Release|Any CPU
146+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
147+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
148+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
149+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.Build.0 = Release|Any CPU
150+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
151+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
152+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
153+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.Build.0 = Release|Any CPU
142154
EndGlobalSection
143155
GlobalSection(SolutionProperties) = preSolution
144156
HideSolutionNode = FALSE
@@ -165,5 +177,7 @@ Global
165177
{B446D481-B5A3-4509-8933-C4CF6DA9B147} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
166178
{F7C6368F-29DC-4F70-AA0E-B3C340F9E1AB} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
167179
{282AD5C5-099A-403D-B415-29AA88A701EC} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
180+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
181+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
168182
EndGlobalSection
169183
EndGlobal

release-please-config.json

+10
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
"extra-files": [
9393
"OpenFeature.Contrib.Providers.EnvVar.csproj"
9494
]
95+
},
96+
"src/OpenFeature.Contrib.Providers.Schematic": {
97+
"package-name": "OpenFeature.Contrib.Providers.Schematic",
98+
"release-type": "simple",
99+
"bump-minor-pre-major": true,
100+
"bump-patch-for-minor-pre-major": true,
101+
"versioning": "default",
102+
"extra-files": [
103+
"OpenFeature.Contrib.Providers.Schematic.csproj"
104+
]
95105
}
96106
},
97107
"changelog-sections": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageId>OpenFeature.Contrib.Providers.Schematic</PackageId>
5+
<VersionNumber>0.1.0</VersionNumber> <!--x-release-please-version -->
6+
<VersionPrefix>$(VersionNumber)</VersionPrefix>
7+
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
8+
<FileVersion>$(VersionNumber)</FileVersion>
9+
<Description>Schematic provider for .NET</Description>
10+
<PackageReadmeFile>README.md</PackageReadmeFile>
11+
<Authors>Benjamin Papillon</Authors>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<!-- make the internal methods visble to our test project -->
15+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
16+
<_Parameter1>$(MSBuildProjectName).Test</_Parameter1>
17+
</AssemblyAttribute>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="SchematicHQ.Client" Version="1.0.8" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<None Include="README.md" Pack="true" PackagePath="\" />
26+
</ItemGroup>
27+
28+
</Project>
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Schematic .NET Provider
2+
3+
The Schematic provider allows you to connect to your Schematic instance through the OpenFeature SDK
4+
5+
# .Net SDK usage
6+
7+
## Requirements
8+
9+
- open-feature/dotnet-sdk v1.5.0 > v2.0.0
10+
11+
## Install dependencies
12+
13+
The first things we will do is install the **Open Feature SDK** and the **Schematic OpenFeature provider**.
14+
15+
### .NET Cli
16+
```shell
17+
dotnet add package OpenFeature.Contrib.Providers.Schematic
18+
```
19+
### Package Manager
20+
21+
```shell
22+
NuGet\Install-Package OpenFeature.Contrib.Providers.Schematic
23+
```
24+
### Package Reference
25+
26+
```xml
27+
<PackageReference Include="OpenFeature.Contrib.Providers.Schematic" />
28+
```
29+
### Paket cli
30+
31+
```shell
32+
paket add OpenFeature.Contrib.Providers.Schematic
33+
```
34+
35+
### Cake
36+
37+
```shell
38+
// Install OpenFeature.Contrib.Providers.Schematic as a Cake Addin
39+
#addin nuget:?package=OpenFeature.Contrib.Providers.Schematic
40+
41+
// Install OpenFeature.Contrib.Providers.Schematic as a Cake Tool
42+
#tool nuget:?package=OpenFeature.Contrib.Providers.Schematic
43+
```
44+
45+
## Using the Schematic Provider with the OpenFeature SDK
46+
47+
To use Schematic as an OpenFeature provider, define your provider and Schematic settings.
48+
49+
```csharp
50+
using OpenFeature;
51+
using OpenFeature.Contrib.Providers.Schematic;
52+
using System;
53+
54+
var schematicProvider = new SchematicProvider("your-api-key");
55+
56+
// Set the schematicProvider as the provider for the OpenFeature SDK
57+
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider);
58+
59+
// Get an OpenFeature client
60+
var client = OpenFeature.Api.Instance.GetClient("my-app");
61+
62+
// Set company and/or user context
63+
var context = EvaluationContext.Builder()
64+
.Set("company", new Dictionary<string, string> {
65+
{ "id", "your-company-id" },
66+
})
67+
.Set("user", new Dictionary<string, string> {
68+
{ "id", "your-user-id" },
69+
})
70+
.Build();
71+
72+
// Evaluate a flag
73+
var val = await client.GetBooleanValueAsync("your-flag-key", false, context);
74+
75+
// Print the value of the 'your-flag-key' feature flag
76+
Console.WriteLine(val);
77+
```
78+
79+
You can also provide additional configuration options to the provider to manage caching behavior, offline mode, and other capabilities:
80+
81+
```csharp
82+
using OpenFeature;
83+
using OpenFeature.Contrib.Providers.Schematic;
84+
using SchematicHQ.Client;
85+
using System;
86+
87+
var options = new ClientOptions
88+
{
89+
Offline = true, // Run in offline mode
90+
FlagDefaults = new Dictionary<string, bool> // Default values for offline mode
91+
{
92+
{ "some-flag-key", true }
93+
},
94+
Logger = new ConsoleLogger(), // Optional custom logger
95+
CacheProviders = new List<ICacheProvider<bool?>> // Optional cache configuration
96+
{
97+
new LocalCache<bool?>(1000, TimeSpan.FromSeconds(30))
98+
}
99+
};
100+
101+
var schematicProvider = new SchematicProvider("your-api-key", options);
102+
103+
// Set the schematicProvider as the provider for the OpenFeature SDK
104+
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider);
105+
106+
// Get an OpenFeature client
107+
var client = OpenFeature.Api.Instance.GetClient("my-app");
108+
109+
// Set company and/or user context
110+
var context = EvaluationContext.Builder()
111+
.Set("company", new Dictionary<string, string> {
112+
{ "id", "your-company-id" },
113+
})
114+
.Set("user", new Dictionary<string, string> {
115+
{ "id", "your-user-id" },
116+
})
117+
.Build();
118+
119+
// Evaluate a flag
120+
var val = await client.GetBooleanValueAsync("your-flag-key", false, context);
121+
122+
// Print the value of the 'your-flag-key' feature flag
123+
Console.WriteLine(val);
124+
```

0 commit comments

Comments
 (0)