Skip to content

Conversation

@kylejuliandev
Copy link
Contributor

This PR

Fixes an issue with the EvaluationContext not being added to the API FeatureClient if a call to AddContext() was made after adding the Provider. For example, the following would fail to inject the EvaluationContext:

builder.Services.AddOpenFeature(featureBuilder =>
{
    featureBuilder
        .AddInMemoryProvider(_ => new Dictionary<string, Flag>()
        {
            {
                "welcome-message", new Flag<bool>(
                    new Dictionary<string, bool> { { "show", true }, { "hide", false } }, "show")
            }
        })
        .AddContext(ctx => ctx.Set("region", "euw"));
});

The fix is not ported to the old Dependency Injection code as we are actively deprecating it.

Related Issues

Fixes #542

Notes

Follow-up Tasks

How to test

Before

Screenshot 2025-10-20 201025

After

image

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@kylejuliandev kylejuliandev requested a review from a team as a code owner October 20, 2025 19:24
@gemini-code-assist
Copy link

Summary of Changes

Hello @kylejuliandev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the OpenFeature .NET SDK's hosting integration that prevented the EvaluationContext from being correctly propagated to FeatureClient instances under specific configuration sequences. The changes simplify the context injection mechanism, making it more robust and independent of the order in which AddProvider() and AddContext() are called, thereby ensuring consistent feature evaluation behavior.

Highlights

  • Reliable EvaluationContext Injection: Fixed an issue where the EvaluationContext was not reliably injected into the FeatureClient if AddContext() was called after AddProvider() during service configuration.
  • Simplified Context Configuration Logic: Removed the IsContextConfigured property from OpenFeatureBuilder and streamlined the AddClient extension method to directly attempt to retrieve and set the EvaluationContext from the service provider, eliminating order-dependent logic.
  • New Test Case: Added a new test, AddClient_WithContextAfterAddProvider_AddsFeatureClient, to specifically validate that the EvaluationContext is correctly applied even when AddContext() is invoked after AddProvider().
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves an issue where the EvaluationContext was not reliably applied to an injected IFeatureClient if AddContext() was called after the client was configured. The fix correctly refactors the client registration by removing the state-dependent IsContextConfigured flag and instead resolving the EvaluationContext from the service provider when the IFeatureClient is requested. This makes the configuration order irrelevant and the behavior more robust. The associated tests have been updated, and a new test correctly validates the fix. The overall change is a significant improvement in correctness and code simplicity.

@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (29e1657) to head (cef609a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
- Coverage   89.76%   89.73%   -0.04%     
==========================================
  Files          77       77              
  Lines        3166     3156      -10     
  Branches      364      364              
==========================================
- Hits         2842     2832      -10     
  Misses        253      253              
  Partials       71       71              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a small question. Other than that looks good to me.

* Removing this was technically a breaking change

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@askpt askpt added this pull request to the merge queue Oct 29, 2025
Merged via the queue into open-feature:main with commit c987b58 Oct 29, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] EvaluationContext is not added with OpenFeatureBuilder

3 participants