Skip to content

feat: Add isolated API instance functionality#740

Open
askpt wants to merge 10 commits intomainfrom
askpt/issue734
Open

feat: Add isolated API instance functionality#740
askpt wants to merge 10 commits intomainfrom
askpt/issue734

Conversation

@askpt
Copy link
Copy Markdown
Member

@askpt askpt commented Apr 12, 2026

Signed-off-by: André Silva 2493377+askpt@users.noreply.github.com

This PR

This pull request introduces support for isolated API instances in the OpenFeature .NET SDK, enabling the creation of independent API objects that do not share state with the global singleton. This is particularly useful for testing, multi-tenant applications, and dependency injection scenarios. The changes also enforce provider ownership rules to prevent a provider from being registered with more than one API instance at a time, and update documentation and tests to demonstrate and verify this new functionality.

Isolated API Instance Support:

  • Added a new static method Api.CreateIsolated() that creates a fully independent Api instance, with its own providers, context, hooks, and event handlers. These instances do not share state with the global singleton or with each other.
  • Enforced provider ownership by adding a _boundApiInstance field to FeatureProvider and validating that a provider is not registered with more than one API instance at a time. Attempts to do so will throw an InvalidOperationException. Ownership is cleared when a provider is shut down. [1] [2] [3] [4] [5] [6]

Documentation and Sample Updates:

  • Updated samples/Console/README.md and samples/Console/app.cs to demonstrate the creation and use of isolated API instances, including example flag definitions and evaluation. [1] [2]

Testing Enhancements:

  • Added a new test TestIsolatedApiAsync() in test/OpenFeature.AotCompatibility/Program.cs to verify the creation, independence, and shutdown of isolated API instances. [1] [2]

Related Issues

Fixes #734

askpt added 6 commits April 11, 2026 13:51
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…Api class

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.51%. Comparing base (98c394f) to head (529bec4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #740      +/-   ##
==========================================
+ Coverage   93.46%   93.51%   +0.05%     
==========================================
  Files          68       68              
  Lines        2952     2975      +23     
  Branches      350      354       +4     
==========================================
+ Hits         2759     2782      +23     
  Misses        135      135              
  Partials       58       58              

☔ 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.

Comment thread test/OpenFeature.Tests/IsolatedApiTests.cs Fixed
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Copy link
Copy Markdown

@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 implements isolated API instances, enabling the creation of independent OpenFeature API instances that maintain their own providers, hooks, and evaluation contexts. The implementation includes a thread-safe mechanism to prevent a single provider from being registered with multiple API instances concurrently. Documentation, usage samples, and extensive unit and AOT compatibility tests have been added. Feedback highlights a potential NullReferenceException in the provider ownership validation if a null provider is passed to the registration methods.

Comment thread src/OpenFeature/Api.cs
@askpt askpt marked this pull request as ready for review April 15, 2026 15:04
@askpt askpt requested a review from a team as a code owner April 15, 2026 15:04
Comment thread src/OpenFeature/Api.cs
Comment thread test/OpenFeature.Tests/IsolatedApiTests.cs
Comment thread test/OpenFeature.Tests/IsolatedApiTests.cs Outdated
…olated API tests

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Comment thread test/OpenFeature.Tests/IsolatedApiTests.cs Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
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.

Support isolated API instances

2 participants