Skip to content

Commit 66f1bd8

Browse files
committed
feat: Adding OpenFeature provider for Schematic
Signed-off-by: Ben Papillon <[email protected]>
1 parent 9ae74e6 commit 66f1bd8

9 files changed

+606
-0
lines changed

DotnetSdkContrib.sln

+14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Provide
4545
EndProject
4646
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Flipt.Test", "test\OpenFeature.Contrib.Providers.Flipt.Test\OpenFeature.Contrib.Providers.Flipt.Test.csproj", "{B446D481-B5A3-4509-8933-C4CF6DA9B147}"
4747
EndProject
48+
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}"
49+
EndProject
50+
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}"
51+
EndProject
4852
Global
4953
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5054
Debug|Any CPU = Debug|Any CPU
@@ -127,6 +131,14 @@ Global
127131
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Debug|Any CPU.Build.0 = Debug|Any CPU
128132
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Release|Any CPU.ActiveCfg = Release|Any CPU
129133
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Release|Any CPU.Build.0 = Release|Any CPU
134+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
135+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
136+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
137+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.Build.0 = Release|Any CPU
138+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
139+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
140+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
141+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.Build.0 = Release|Any CPU
130142
EndGlobalSection
131143
GlobalSection(SolutionProperties) = preSolution
132144
HideSolutionNode = FALSE
@@ -151,5 +163,7 @@ Global
151163
{F3080350-B0AB-4D59-B416-50CC38C99087} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
152164
{5ECF7DBF-FE64-40A2-BF39-239DE173DA4B} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
153165
{B446D481-B5A3-4509-8933-C4CF6DA9B147} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
166+
{CF1AB517-1D51-455F-80C0-56B4856E6A6B} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
167+
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
154168
EndGlobalSection
155169
EndGlobal

release-please-config.json

+10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@
8282
"extra-files": [
8383
"OpenFeature.Contrib.Providers.Flipt.csproj"
8484
]
85+
},
86+
"src/OpenFeature.Contrib.Providers.Schematic": {
87+
"package-name": "OpenFeature.Contrib.Providers.Schematic",
88+
"release-type": "simple",
89+
"bump-minor-pre-major": true,
90+
"bump-patch-for-minor-pre-major": true,
91+
"versioning": "default",
92+
"extra-files": [
93+
"OpenFeature.Contrib.Providers.Schematic.csproj"
94+
]
8595
}
8696
},
8797
"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.6" />
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 SchematicFeatureProvider("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 SchematicFeatureProvider("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)