Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Restore IsContextConfigured and following unit test assertions
* Removing this was technically a breaking change

Signed-off-by: Kyle Julian <[email protected]>
  • Loading branch information
kylejuliandev committed Oct 22, 2025
commit cef609a7de56dd22cb3c4bb17abdf44d0971b0d5
7 changes: 7 additions & 0 deletions src/OpenFeature.Hosting/OpenFeatureBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public class OpenFeatureBuilder(IServiceCollection services)
/// <summary> The services being configured. </summary>
public IServiceCollection Services { get; } = services;

/// <summary>
/// Indicates whether the evaluation context has been configured.
/// This property is used to determine if specific configurations or services
/// should be initialized based on the presence of an evaluation context.
/// </summary>
public bool IsContextConfigured { get; internal set; }

/// <summary>
/// Indicates whether the policy has been configured.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/OpenFeature.Hosting/OpenFeatureBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static OpenFeatureBuilder AddContext(this OpenFeatureBuilder builder, Act
Guard.ThrowIfNull(builder);
Guard.ThrowIfNull(configure);

builder.IsContextConfigured = true;
builder.Services.TryAddTransient(provider =>
{
var contextBuilder = EvaluationContext.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void AddContext_Delegate_ShouldAddServiceToCollection(bool useServiceProv

// Assert
Assert.Equal(_systemUnderTest, featureBuilder);
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.Single(_services, serviceDescriptor =>
serviceDescriptor.ServiceType == typeof(EvaluationContext) &&
serviceDescriptor.Lifetime == ServiceLifetime.Transient);
Expand All @@ -51,6 +52,7 @@ public void AddContext_Delegate_ShouldCorrectlyHandles(bool useServiceProviderDe
var context = serviceProvider.GetService<EvaluationContext>();

// Assert
Assert.True(_systemUnderTest.IsContextConfigured, "The context should be configured.");
Assert.NotNull(context);
Assert.True(delegateCalled, "The delegate should be invoked.");
}
Expand All @@ -76,6 +78,7 @@ public void AddProvider_ShouldAddProviderToCollection(int providerRegistrationTy
};

// Assert
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
Expand Down Expand Up @@ -166,6 +169,7 @@ public void AddProvider_VerifiesDefaultAndDomainBoundProvidersBasedOnConfigurati
};

// Assert
Assert.False(_systemUnderTest.IsContextConfigured, "The context should not be configured.");
Assert.Equal(expectsDefaultProvider, _systemUnderTest.HasDefaultProvider);
Assert.False(_systemUnderTest.IsPolicyConfigured, "The policy should not be configured.");
Assert.Equal(expectsDomainBoundProvider, _systemUnderTest.DomainBoundProviderRegistrationCount);
Expand Down