-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: Add Dependency Injection and Hosting support for OpenFeature #310
base: main
Are you sure you want to change the base?
feat: Add Dependency Injection and Hosting support for OpenFeature #310
Conversation
…re/NoOpFeatureProvider
…rDoesNotExist test
Hey @arttonoyan! The build is failing because of compliance. Could you please follow these steps? https://github.com/open-feature/dotnet-sdk/pull/310/checks?check_run_id=31479940982 |
Signed-off-by: Artyom Tonoyan <[email protected]>
Signed-off-by: Artyom Tonoyan <[email protected]>
Signed-off-by: Artyom Tonoyan <[email protected]>
Signed-off-by: Artyom Tonoyan <[email protected]>
Signed-off-by: Artyom Tonoyan <[email protected]>
@arttonoyan I've approved arttonoyan#1 (review) with some minor comments, but I also want to make sure before we release that we mark everything in the new DI namespace as experimental. |
Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
…ns.cs Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
…ns.cs Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
…ns.cs Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
…ns.cs Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
…ns.cs Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
feat: Support Domain-Scoped Providers configuration for FeatureClient
@arttonoyan regartding this comment, the main reason I wanted the DI namespace is because I really wanted to make it clear what is subject to change, and what is not, and putting those things in the DI namespace helped with that. However, if we add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am adding a couple of suggestions about the namespace.
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Options; | ||
using OpenFeature.DependencyInjection; | ||
using OpenFeature.Model; | ||
|
||
namespace OpenFeature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace OpenFeature; | |
namespace OpenFeature.DependencyInjection; |
using OpenFeature.Model; | ||
using Microsoft.Extensions.Options; | ||
using OpenFeature.DependencyInjection; | ||
using OpenFeature.DependencyInjection.Internal; | ||
|
||
namespace OpenFeature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace OpenFeature; | |
namespace OpenFeature.DependencyInjection; |
@@ -1,4 +1,5 @@ | |||
using Microsoft.Extensions.DependencyInjection; | |||
using OpenFeature.DependencyInjection; | |||
|
|||
namespace OpenFeature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace OpenFeature; | |
namespace OpenFeature.Hosting; |
Co-authored-by: André Silva <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
Co-authored-by: André Silva <[email protected]> Signed-off-by: Artyom Tonoyan <[email protected]>
Thanks, @askpt, for the suggestion. Let me explain why I prefer not to change these namespaces: Grouping using OpenFeature.Hosting;
using OpenFeature.DependencyInjection; As the project grows, this list could expand, increasing complexity. Keeping everything under one namespace simplifies configuration and improves the developer experience by reducing clutter and creating a cohesive setup process. Additionally, this approach supports a clear, consistent API structure, making it easier to manage and recall namespaces. |
I understand your point, but from a user who is consuming the "packages", it would be weird to be named "OpenFeature". I suggest changing the "package" name or grouping both into "OpenFeature.DependencyInjection" so it won't be confusing. Imagine you are a new user using the Thank you so much for your work and input. If you need any help with the |
I understand your perspective, and you’re right that intuitive package naming is important for new users. The approach I’m suggesting is actually similar to how Microsoft organizes core libraries - grouping related APIs in a way that prioritizes logical grouping over a strict alignment with package names. This doesn’t tend to complicate usage, as Visual Studio (or other IDEs) makes it easy to navigate by pressing F12 to go directly to code definitions, where the library and assembly information are clearly visible. However, I also recognize the importance of clarity for new users. If you feel strongly that renaming or grouping under OpenFeature.DependencyInjection will better align expectations, I’ll change. And @askpt, if you’re able to lend a hand with this as well, that would be great! |
@askpt to clarify, the intent was not to release a separate nuget artifact for these changes (we don't even have the publishing mechanisms in this repo to support that); the idea was just to add new functionality marked as experimental using the @arttonoyan You should be able to annotate all the new classes or functions (basically anything a user would touch) like this: #if !NET462
[System.Diagnostics.CodeAnalysis.Experimental(Constants.NewDiFeatures)]
#endif Where Note that this attribute doesn't exist in .NET framework (462) so you need to add the prepreoceessor directive ( |
Thanks, @toddbaert! I’m working on it, though it’s impacting quite a few classes. Another approach could be to build pre-release packages and mark the package itself as experimental, which aligns with NuGet's recommendations for experimental features: Pre-release Packages. To make it clear for users, we could set the version <PackageReleaseNotes>This is an experimental version. Features may change without notice.</PackageReleaseNotes>
<Description>Experimental package for testing new features. Not recommended for production use.</Description> This would help users recognize the package as experimental and avoid unintended use in production. What do you think? |
@toddbaert I've created a new PR to add the Key Points:
I’ve created this change in a separate branch, as I think marking the package as experimental is more convenient, as mentioned above. However, the PR is open, and I'm open to feedback – please feel free to decide if this is the best approach for this package. |
@arttonoyan The problem is we dont want to mark the entire SDK as experimental, and these features will be included in all subsequent releases, so I don't think an experimental version number can help, unless we want to merge these features to a non-main branch and maintain that along side the main branch (I'm not in favor of this for the maintenance burden it creates). If you can add |
Note
This initial version of OpenFeature.DependencyInjection and OpenFeature.Hosting introduces basic provider management and lifecycle support for .NET Dependency Injection environments. While I haven't included extensive tests, particularly for the Hosting project, if this approach is approved and the scope is considered sufficient for the first DI and Hosting release, I will expand the test coverage to include both unit and integration tests. Additionally, I'll provide a sample application to demonstrate the usage.
This pull request introduces key features and improvements to the OpenFeature project, focusing on Dependency Injection and Hosting support:
OpenFeature.DependencyInjection Project:
OpenFeatureBuilder
, includingOpenFeatureBuilderExtensions
for seamless integration.IFeatureLifecycleManager
interface and its implementation.AddProvider
extension method for easy provider configuration.OpenFeatureServiceCollectionExtensions
for service registration.OpenFeature.Hosting Project:
HostedFeatureLifecycleService
to manage the lifecycle of feature providers in hosted environments.Testing Enhancements:
OpenFeatureBuilderExtensionsTests
andOpenFeatureServiceCollectionExtensionsTests
.NoOpFeatureProvider
implementation for better test coverage.These changes significantly improve OpenFeature's extensibility and lifecycle management for feature providers within Dependency Injection (DI) and hosted environments.
NuGet Packages for installation:
Usage Example: