-
Notifications
You must be signed in to change notification settings - Fork 22
fix: update DI lifecycle to use container instead of static instance #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…nd context retrieval Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #534 +/- ##
==========================================
+ Coverage 88.45% 88.48% +0.03%
==========================================
Files 50 50
Lines 2096 2102 +6
Branches 245 245
==========================================
+ Hits 1854 1860 +6
Misses 191 191
Partials 51 51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
toddbaert
reviewed
Jul 29, 2025
src/OpenFeature.DependencyInjection/OpenFeatureServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
…jection Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…nd improve provider access Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
kylejuliandev
approved these changes
Jul 29, 2025
toddbaert
approved these changes
Jul 30, 2025
This was referenced Jul 31, 2025
Closed
This was referenced Nov 26, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR
This pull request refactors the
Apiclass and its integration withFeatureClientto improve testability and dependency management by replacing the singleton access pattern with dependency injection. It also includes minor project configuration updates. Below are the key changes grouped by theme:Refactoring
Apiand Dependency Injection:Apiconstructor fromprivatetointernal, allowing it to be instantiated directly for dependency injection purposes (src/OpenFeature/Api.cs, src/OpenFeature/Api.csL35-R35).AddOpenFeatureinOpenFeatureServiceCollectionExtensionsto register a new instance ofApiinstead of using the singletonApi.Instance(src/OpenFeature.DependencyInjection/OpenFeatureServiceCollectionExtensions.cs, src/OpenFeature.DependencyInjection/OpenFeatureServiceCollectionExtensions.csL27-R27).FeatureClientto accept anApiinstance as a constructor parameter, defaulting toApi.Instanceif not provided. Updated all internal references to use the injectedApiinstance (src/OpenFeature/OpenFeatureClient.cs, [1] [2] [3] [4] [5].Updates to
FeatureClient:_apifield to store the injectedApiinstance and replaced all direct calls toApi.Instancewith_apito improve testability (src/OpenFeature/OpenFeatureClient.cs, [1] [2] [3].Project Configuration:
InternalsVisibleToforOpenFeature.DependencyInjectionto allow access to internal members of theOpenFeatureassembly (src/OpenFeature/OpenFeature.csproj, src/OpenFeature/OpenFeature.csprojR22).Related Issues
Fixes #533
Notes
As pointed out, I made a couple of changes in the
FeatureClientclass to use the same reference all the time for theApi. I checked the rest of the codebase and theApi.Instanceis only used in the testing projects.This change doesn't affect any external methods.