Skip to content

Conversation

@kylejuliandev
Copy link
Contributor

@kylejuliandev kylejuliandev commented May 7, 2025

This PR

  • Introduces a new extension method in the OpenFeature.DependencyInjection package which allows consumers to add, at a global/api level, a handler.

Example usage:

builder.Services.AddOpenFeature(feature =>
{
    feature.AddHostedFeatureLifecycle()
        .AddInMemoryProvider()
        .AddHandler(ProviderEventTypes.ProviderReady, (@event) => { Console.WriteLine("{0}", @event!.ProviderName); })
        .AddHandler(ProviderEventTypes.ProviderReady, sp => (@event) =>
        {
            var logger = sp.GetRequiredService<ILogger<Program>>();
            logger.LogInformation("Provider Ready");
        });
});

Related Issues

Fixes #457

Notes

Follow-up Tasks

How to test

@kylejuliandev kylejuliandev requested a review from a team as a code owner May 7, 2025 19:24
@codecov
Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.87%. Comparing base (0a5ab0c) to head (51645c2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #462      +/-   ##
==========================================
+ Coverage   86.72%   86.87%   +0.14%     
==========================================
  Files          42       43       +1     
  Lines        1703     1722      +19     
  Branches      179      180       +1     
==========================================
+ Hits         1477     1496      +19     
  Misses        187      187              
  Partials       39       39              

☔ 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

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

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

Looks good to me. I just had a question about the random name generator but it isn't a blocker.

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.

Looks good to me. Great work. Added a couple of suggestions 👍

* Add check if passed in handler name is an empty or null string

Signed-off-by: Kyle Julian <[email protected]>
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.

It is a very minor request! We should also validate for inputs like whitespace.

Also, @arttonoyan, would you mind double-checking?

* Ensure that calling AddHandler multiple times will actually add all
  instances to the underlying OpenFeature API
* Add unit tests to cover this behaviour

Signed-off-by: Kyle Julian <[email protected]>
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.

LGTM. Just a minor question, and should be ready to merge! Thanks!

* Throw ArgumentException when HandlerName is null or empty
* Use primary constructor in EventHandlerDelegateWrapper

Signed-off-by: Kyle Julian <[email protected]>
@askpt
Copy link
Member

askpt commented May 10, 2025

LGTM! If @arttonoyan is happy with the changes @kylejuliandev made, we can merge it 👍
Thanks for your efforts!

* Ensure when multiple handlers are registered that they are both
  registered
* Tweak CreateServerAsync to make it easier to extend dependency
  injection tests

Signed-off-by: Kyle Julian <[email protected]>
* Remove any unnecessary unit tests
* Update integration tests to use openFeatureBuilder for easily
  adjusting the Arrange part of each test

Signed-off-by: Kyle Julian <[email protected]>
@askpt askpt added this pull request to the merge queue May 12, 2025
Merged via the queue into open-feature:main with commit ff414b8 May 12, 2025
18 checks passed
This was referenced Dec 17, 2025
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] Add Events to the global instance of OpenFeature using DI syntax

4 participants