Skip to content

Conversation

arttonoyan
Copy link
Contributor

This PR

Extract the minimal, provider-agnostic DI surface into a new package: OpenFeature.DependencyInjection.Abstractions.
This isolates the contracts and lightweight wiring needed to integrate any OpenFeature provider without pulling in a concrete implementation.

Related Issues

Fixes #587

Notes

  • Options split: Extracted provider-agnostic configuration from OpenFeatureOptions into a new base options type: OpenFeatureProviderOptions.
  • Inheritance: OpenFeatureOptions now inherits from OpenFeatureProviderOptions.
  • Internal wiring update: Internal configuration that previously targeted OpenFeatureOptions now targets OpenFeatureProviderOptions.

Before (internal)

services.AddOptions<OpenFeatureOptions>()
    .Configure(options =>
    {
        options.AddProviderName(null);
    });

After (internal)

services.AddOptions<OpenFeatureProviderOptions>()
    .Configure(options =>
    {
        options.AddProviderName(null);
    });

Note: This is an internal refactor. It does not affect consumers unless they were directly modifying OpenFeatureOptions via DI options configuration (which is not a supported/typical usage).


Impact

  • No new functionality.
  • Behavior unchanged at runtime (same provider selection, same evaluation outcomes, same logs).
  • Binary/source compatibility: Consumers using the documented extension methods and standard registration remain unaffected.
  • Potential touchpoints: Only internal code paths (or unconventional consumer code directly configuring OpenFeatureOptions) require updates to target OpenFeatureProviderOptions.

How to test

This is a regression-only refactor.

Expectations

  • All existing unit/integration tests pass unchanged.
  • No DI resolution or startup configuration differences.

Introduced a new project, `OpenFeature.DependencyInjection.Abstractions`, to the solution. This project supports dependency injection abstractions and targets multiple frameworks (`netstandard2.0`, `net8.0`, `net9.0`, `net462`) for broad compatibility.

Configured the project with the `Microsoft.NET.Sdk` SDK and set the root namespace to `OpenFeature.DependencyInjection.Abstractions`. Added dependencies on `Microsoft.Extensions.DependencyInjection.Abstractions` and `Microsoft.Extensions.Options` to enable DI and options configuration.
Refactored the OpenFeature framework to introduce `OpenFeatureProviderBuilder`, enhancing support for dependency injection and provider management.

- Changed namespaces to align with DI abstractions.
- Made `FeatureCodes` public for broader accessibility.
- Added `InternalsVisibleTo` for testing and project references.
- Introduced `OpenFeatureProviderBuilder` for managing providers and policies.
- Added extension methods for provider and policy registration.
- Refactored `OpenFeatureBuilder` to inherit from `OpenFeatureProviderBuilder`.
- Consolidated shared functionality in `OpenFeatureProviderOptions`.
- Updated `FeatureBuilderExtensions` and `InMemoryProviderOptions` to use the new abstraction.
- Updated tests to reflect new method signatures and hierarchy.
- Removed redundant methods and properties, improving code organization.

These changes improve maintainability, extensibility, and alignment with modern DI patterns.
Simplified the `AddProvider` API by removing the `TFeatureProvider` generic type parameter and directly using the `FeatureProvider` type. Updated the `TOptions` parameter to ensure it derives from `OpenFeatureProviderOptions`.

Added a `<ProjectReference>` to `OpenFeature.csproj` in `OpenFeature.DependencyInjection.Abstractions.csproj`. Updated `OpenFeatureOptions` to `OpenFeatureProviderOptions` in the default name selector policy.

Refactored `AddInMemoryProvider` methods to align with the new API. Updated tests in `OpenFeatureBuilderExtensionsTests` to reflect the changes and validate the updated functionality.

Performed general code cleanup, including XML documentation updates, to improve clarity and maintain consistency across the codebase.
Refactored `FeatureLifecycleManager` to modularize provider, hook, and handler initialization with new methods: `InitializeProvidersAsync`, `InitializeHooks`, and `InitializeHandlers`. Updated `EnsureInitializedAsync` to use these methods for improved readability and maintainability.

Revised `AddInMemoryProvider` in `FeatureBuilderExtensions` to use a generic `FeatureProvider` abstraction. Adjusted `CreateProvider` methods accordingly.

Improved code clarity in `FeatureFlagIntegrationTest` by renaming variables for consistency and removing redundant assignments.
Updated FeatureLifecycleManagerTests to replace OpenFeatureOptions
with OpenFeatureProviderOptions for configuring feature providers.
Added support for hooks and keyed singletons to enhance modularity.
Introduced additional feature flag retrieval in FeatureFlagIntegrationTest.
Added dependency on OpenFeature.DependencyInjection.Abstractions.
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 96.85039% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.44%. Comparing base (d15960c) to head (acade51).

Files with missing lines Patch % Lines
...stractions/OpenFeatureProviderBuilderExtensions.cs 90.24% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #596      +/-   ##
==========================================
- Coverage   89.52%   89.44%   -0.09%     
==========================================
  Files          77       80       +3     
  Lines        3084     3097      +13     
  Branches      350      355       +5     
==========================================
+ Hits         2761     2770       +9     
  Misses        256      256              
- Partials       67       71       +4     

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

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.

[FEATURE] Minimal OpenFeature.DependencyInjection.Abstractions with Builder API (Hosting retains DI registrations)

1 participant