Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions examples/OpenFeature/OpenFeatureExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ public static async Task Main(string[] args)
// Get the OpenFeature client
var client = Api.Instance.GetClient();

// Evaluate a feature flag
var isFeatureEnabled = await client.GetBooleanValue("new-feature", false, context);
// Evaluate a feature flag (using OpenFeature 2.x async methods)
var isFeatureEnabled = await client.GetBooleanValueAsync("new-feature", false, context);
Console.WriteLine($"Feature 'new-feature' is {(isFeatureEnabled ? "enabled" : "disabled")}");

// Get detailed flag evaluation
var flagDetails = await client.GetBooleanDetails("new-feature", false, context);
// Get detailed flag evaluation (using OpenFeature 2.x async methods)
var flagDetails = await client.GetBooleanDetailsAsync("new-feature", false, context);
Console.WriteLine($"Flag evaluation reason: {flagDetails.Reason}");
Console.WriteLine($"Flag variant: {flagDetails.Variant}");

// Track an event using the provider
await provider.TrackEventAsync("feature_viewed", context, new Dictionary<string, object>
Expand All @@ -53,8 +54,15 @@ public static async Task Main(string[] args)
["enabled"] = isFeatureEnabled
});

// Demonstrate other flag types (they return default values with error reasons)
var stringFlag = await client.GetStringValueAsync("config-value", "default", context);
Console.WriteLine($"String flag value: {stringFlag}");

var intFlag = await client.GetIntegerValueAsync("max-items", 10, context);
Console.WriteLine($"Integer flag value: {intFlag}");

// Shutdown
await Api.Instance.Shutdown();
await Api.Instance.ShutdownAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task ResolveBooleanValue_InOfflineMode_ReturnsDefaultValue()
var context = EvaluationContext.Empty;

// Act
var result = await provider.ResolveBooleanValue("test-flag", false, context);
var result = await provider.ResolveBooleanValueAsync("test-flag", false, context);

// Assert
Assert.That(result.FlagKey, Is.EqualTo("test-flag"));
Expand All @@ -63,7 +63,7 @@ public async Task ResolveBooleanValue_FlagNotInDefaults_ReturnsFalse()

// Act
// In offline mode, Schematic returns false for flags not in defaults, regardless of the provided default
var result = await provider.ResolveBooleanValue("non-existent-flag", true, EvaluationContext.Empty);
var result = await provider.ResolveBooleanValueAsync("non-existent-flag", true, EvaluationContext.Empty);

// Assert
Assert.That(result.Value, Is.False); // Schematic always returns false for unknown flags in offline mode
Expand Down Expand Up @@ -98,7 +98,7 @@ public async Task ResolveBooleanValue_WithContext_ExtractsCorrectly()
.Build();

// Act - In offline mode, context is ignored but should not cause errors
var result = await provider.ResolveBooleanValue("feature-x", false, context);
var result = await provider.ResolveBooleanValueAsync("feature-x", false, context);

// Assert
Assert.That(result.Value, Is.True);
Expand All @@ -123,7 +123,7 @@ public async Task ResolveBooleanValue_WithTargetingKey_HandlesCorrectly()
.Build();

// Act
var result = await provider.ResolveBooleanValue("test-flag", false, context);
var result = await provider.ResolveBooleanValueAsync("test-flag", false, context);

// Assert
Assert.That(result.Value, Is.True);
Expand All @@ -137,7 +137,7 @@ public async Task ResolveStringValue_ReturnsUnsupportedType()
var context = EvaluationContext.Empty;

// Act
var result = await provider.ResolveStringValue("test-flag", "default", context);
var result = await provider.ResolveStringValueAsync("test-flag", "default", context);

// Assert
Assert.That(result.FlagKey, Is.EqualTo("test-flag"));
Expand All @@ -154,7 +154,7 @@ public async Task ResolveIntegerValue_ReturnsUnsupportedType()
var provider = new SchematicProvider("test-key");

// Act
var result = await provider.ResolveIntegerValue("test-flag", 42, EvaluationContext.Empty);
var result = await provider.ResolveIntegerValueAsync("test-flag", 42, EvaluationContext.Empty);

// Assert
Assert.That(result.Value, Is.EqualTo(42));
Expand All @@ -169,7 +169,7 @@ public async Task ResolveDoubleValue_ReturnsUnsupportedType()
var provider = new SchematicProvider("test-key");

// Act
var result = await provider.ResolveDoubleValue("test-flag", 3.14, EvaluationContext.Empty);
var result = await provider.ResolveDoubleValueAsync("test-flag", 3.14, EvaluationContext.Empty);

// Assert
Assert.That(result.Value, Is.EqualTo(3.14));
Expand All @@ -185,7 +185,7 @@ public async Task ResolveStructureValue_ReturnsUnsupportedType()
var defaultValue = new Value(new Structure(new Dictionary<string, Value>()));

// Act
var result = await provider.ResolveStructureValue("test-flag", defaultValue, EvaluationContext.Empty);
var result = await provider.ResolveStructureValueAsync("test-flag", defaultValue, EvaluationContext.Empty);

// Assert
Assert.That(result.Value, Is.EqualTo(defaultValue));
Expand All @@ -200,7 +200,7 @@ public async Task Initialize_CompletesSuccessfully()
var provider = new SchematicProvider("test-key");

// Act & Assert (should not throw)
await provider.Initialize(EvaluationContext.Empty);
await provider.InitializeAsync(EvaluationContext.Empty);
}

[Test]
Expand All @@ -211,7 +211,7 @@ public async Task Shutdown_InOfflineMode_CompletesSuccessfully()
var provider = new SchematicProvider("test-key", options);

// Act & Assert (should not throw)
await provider.Shutdown();
await provider.ShutdownAsync();
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Configure additional MSBuild properties for your project in this file:
-->
<Project>
<ItemGroup>
<PackageReference Include="OpenFeature" Version="1.5.1" />
<PackageReference Include="OpenFeature" Version="2.9.0" />
</ItemGroup>
</Project>
33 changes: 19 additions & 14 deletions src/SchematicHQ.Client/OpenFeature/SchematicProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ public override Metadata GetMetadata()
}

/// <inheritdoc/>
public override async Task<ResolutionDetails<bool>> ResolveBooleanValue(
public override async Task<ResolutionDetails<bool>> ResolveBooleanValueAsync(
string flagKey,
bool defaultValue,
EvaluationContext context = null)
EvaluationContext? context = null,
CancellationToken cancellationToken = default)
{
try
{
Expand Down Expand Up @@ -92,10 +93,11 @@ public override async Task<ResolutionDetails<bool>> ResolveBooleanValue(
}

/// <inheritdoc/>
public override Task<ResolutionDetails<string>> ResolveStringValue(
public override Task<ResolutionDetails<string>> ResolveStringValueAsync(
string flagKey,
string defaultValue,
EvaluationContext context = null)
EvaluationContext? context = null,
CancellationToken cancellationToken = default)
{
return Task.FromResult(new ResolutionDetails<string>(
flagKey: flagKey,
Expand All @@ -107,10 +109,11 @@ public override Task<ResolutionDetails<string>> ResolveStringValue(
}

/// <inheritdoc/>
public override Task<ResolutionDetails<int>> ResolveIntegerValue(
public override Task<ResolutionDetails<int>> ResolveIntegerValueAsync(
string flagKey,
int defaultValue,
EvaluationContext context = null)
EvaluationContext? context = null,
CancellationToken cancellationToken = default)
{
return Task.FromResult(new ResolutionDetails<int>(
flagKey: flagKey,
Expand All @@ -122,10 +125,11 @@ public override Task<ResolutionDetails<int>> ResolveIntegerValue(
}

/// <inheritdoc/>
public override Task<ResolutionDetails<double>> ResolveDoubleValue(
public override Task<ResolutionDetails<double>> ResolveDoubleValueAsync(
string flagKey,
double defaultValue,
EvaluationContext context = null)
EvaluationContext? context = null,
CancellationToken cancellationToken = default)
{
return Task.FromResult(new ResolutionDetails<double>(
flagKey: flagKey,
Expand All @@ -137,10 +141,11 @@ public override Task<ResolutionDetails<double>> ResolveDoubleValue(
}

/// <inheritdoc/>
public override Task<ResolutionDetails<Value>> ResolveStructureValue(
public override Task<ResolutionDetails<Value>> ResolveStructureValueAsync(
string flagKey,
Value defaultValue,
EvaluationContext context = null)
EvaluationContext? context = null,
CancellationToken cancellationToken = default)
{
return Task.FromResult(new ResolutionDetails<Value>(
flagKey: flagKey,
Expand All @@ -152,14 +157,14 @@ public override Task<ResolutionDetails<Value>> ResolveStructureValue(
}

/// <inheritdoc/>
public override Task Initialize(EvaluationContext context)
public override Task InitializeAsync(EvaluationContext? context, CancellationToken cancellationToken = default)
{
_options.Logger?.Info("Schematic provider initialized");
return Task.CompletedTask;
}

/// <inheritdoc/>
public override async Task Shutdown()
public override async Task ShutdownAsync(CancellationToken cancellationToken = default)
{
_options.Logger?.Info("Schematic provider shutting down");
await _schematic.Shutdown().ConfigureAwait(false);
Expand All @@ -173,7 +178,7 @@ public override async Task Shutdown()
/// <param name="traits">Additional event properties.</param>
public Task TrackEventAsync(
string eventName,
EvaluationContext context = null,
EvaluationContext? context = null,
Dictionary<string, object>? traits = null)
{
if (string.IsNullOrWhiteSpace(eventName))
Expand Down Expand Up @@ -206,7 +211,7 @@ public Task TrackEventAsync(
return Task.CompletedTask;
}

private static (Dictionary<string, string>? company, Dictionary<string, string>? user) ExtractContext(EvaluationContext context)
private static (Dictionary<string, string>? company, Dictionary<string, string>? user) ExtractContext(EvaluationContext? context)
{
if (context == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SchematicHQ.Client/SchematicHQ.Client.Custom.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Configure additional MSBuild properties for your project in this file:
<TargetFrameworks>net8.0;</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenFeature" Version="1.5.1" />
<PackageReference Include="OpenFeature" Version="2.9.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.41" />
</ItemGroup>

Expand Down