-
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
Open
arttonoyan
wants to merge
136
commits into
open-feature:main
Choose a base branch
from
arttonoyan:add-dependency-injection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 132 commits
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
963b54c
[SIP-123] feat: Create OpenFeature.DependencyInjection project
arttonoyan a803429
chore: Update TargetFrameworks to net6.0
arttonoyan 79ee277
feat: Create OpenFeatureBuilder record
arttonoyan 9f3c40e
feat: Add OpenFeatureBuilderExtensions
arttonoyan 6786bd8
feat: Add IFeatureLifecycleManager interface and implementation
arttonoyan f373eb0
feat: Add OpenFeatureServiceCollectionExtensions
arttonoyan 1f86298
feat: Add AddProvider extension method in OpenFeatureBuilderExtensions
arttonoyan f1039a2
feat: Add AddProvider extension method in OpenFeatureServiceCollectio…
arttonoyan 5905cc6
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan 6c3c15e
test: Add unit tests for AddProvider method in OpenFeatureBuilderExte…
arttonoyan bd20d40
feat: Replicate NoOpFeatureProvider implementation from src/OpenFeatu…
arttonoyan 441aa4f
test: Update OpenFeatureBuilderExtensionsTests with NoOpFeatureProvid…
arttonoyan fa04665
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan fcea8a6
refactor: Remove ExcludeFromCodeCoverage attribute from FeatureLifecy…
arttonoyan fc8dcab
test: Improve OpenFeatureBuilderExtensionsTests for better coverage a…
arttonoyan 0a996aa
test: Create OpenFeatureServiceCollectionExtensionsTests
arttonoyan 76e1816
feat: Create OpenFeature.Hosting project
arttonoyan 84dd0e0
feat: Add HostedFeatureLifecycleService and related logic
arttonoyan 572d67b
test: Improve EnsureInitializedAsync_ShouldThrowException_WhenProvide…
arttonoyan d7e5fbb
[SIP-123] feat: Create OpenFeature.DependencyInjection project
arttonoyan f60b5d8
chore: Update TargetFrameworks to net6.0
arttonoyan 8b59e53
feat: Create OpenFeatureBuilder record
arttonoyan c644df6
feat: Add OpenFeatureBuilderExtensions
arttonoyan f4f108b
feat: Add IFeatureLifecycleManager interface and implementation
arttonoyan 43bcde9
feat: Add OpenFeatureServiceCollectionExtensions
arttonoyan 47e87c2
feat: Add AddProvider extension method in OpenFeatureBuilderExtensions
arttonoyan 3650de2
feat: Add AddProvider extension method in OpenFeatureServiceCollectio…
arttonoyan 0027489
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan 5638163
test: Add unit tests for AddProvider method in OpenFeatureBuilderExte…
arttonoyan 5de7ceb
feat: Replicate NoOpFeatureProvider implementation from src/OpenFeatu…
arttonoyan 2e99210
test: Update OpenFeatureBuilderExtensionsTests with NoOpFeatureProvid…
arttonoyan 880df92
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan 9258706
refactor: Remove ExcludeFromCodeCoverage attribute from FeatureLifecy…
arttonoyan 19664b0
test: Improve OpenFeatureBuilderExtensionsTests for better coverage a…
arttonoyan 9c21943
test: Create OpenFeatureServiceCollectionExtensionsTests
arttonoyan a23c5ea
feat: Create OpenFeature.Hosting project
arttonoyan 7906a3b
feat: Add HostedFeatureLifecycleService and related logic
arttonoyan 1850159
test: Improve EnsureInitializedAsync_ShouldThrowException_WhenProvide…
arttonoyan 63ead66
Merge branch 'add-dependency-injection' of https://github.com/arttono…
arttonoyan 70708ec
fix(build): Resolve MultiTarget framework build errors
arttonoyan d615b04
chore(deps): update codecov/codecov-action action to v4.5.0 (#272)
renovate[bot] ad95765
chore(deps): update dependency githubactionstestlogger to v2.4.1 (#274)
renovate[bot] ce23cdc
feat!: internally maintain provider status (#276)
toddbaert 7716f4a
chore: cleanup code (#277)
askpt 12d48c2
chore(deps): update actions/upload-artifact action to v4.3.4 (#278)
renovate[bot] 1f0468e
chore(deps): update xunit-dotnet monorepo (#279)
renovate[bot] d480da4
chore(deps): update dependency dotnet-sdk to v8.0.303 (#275)
renovate[bot] cc5f5bc
feat: Drop net7 TFM (#284)
benjiro 90d172c
fix: Should map metadata when converting from ResolutionDetails to Fl…
benjiro 2072e45
feat: back targetingKey with internal map (#287)
toddbaert c503b30
chore(deps): update actions/upload-artifact action to v4.3.5 (#291)
renovate[bot] 9a5a343
feat!: domain instead of client name (#294)
toddbaert be43fcc
chore(deps): update dependency benchmarkdotnet to v0.14.0 (#293)
renovate[bot] 84f8e18
chore(deps): update dependency dotnet-sdk to v8.0.400 (#295)
renovate[bot] 94f4d66
chore: in-memory UpdateFlags to UpdateFlagsAsync (#298)
toddbaert 756a7f7
chore(main): release 2.0.0 (#254)
github-actions[bot] 36b5f8c
chore(deps): update dependency microsoft.net.test.sdk to 17.11.0 (#297)
renovate[bot] c9339ec
chore(deps): update dependency dotnet-sdk to v8.0.401 (#296)
renovate[bot] 980d0be
chore: update release please config (#304)
beeme1mr d4a5e3d
[SIP-123] feat: Create OpenFeature.DependencyInjection project
arttonoyan 8387def
chore: Update TargetFrameworks to net6.0
arttonoyan 5077a1c
feat: Create OpenFeatureBuilder record
arttonoyan 95e8ddc
feat: Add OpenFeatureBuilderExtensions
arttonoyan f157496
feat: Add IFeatureLifecycleManager interface and implementation
arttonoyan 49991ec
feat: Add OpenFeatureServiceCollectionExtensions
arttonoyan 5bc2c47
feat: Add AddProvider extension method in OpenFeatureBuilderExtensions
arttonoyan 9ea9b01
feat: Add AddProvider extension method in OpenFeatureServiceCollectio…
arttonoyan 4066b89
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan 367518b
test: Add unit tests for AddProvider method in OpenFeatureBuilderExte…
arttonoyan 70c269f
feat: Replicate NoOpFeatureProvider implementation from src/OpenFeatu…
arttonoyan b20bc13
test: Update OpenFeatureBuilderExtensionsTests with NoOpFeatureProvid…
arttonoyan c251f56
test: Add OpenFeatureBuilderExtensionsTests
arttonoyan 8b2ab4b
refactor: Remove ExcludeFromCodeCoverage attribute from FeatureLifecy…
arttonoyan 3800447
test: Improve OpenFeatureBuilderExtensionsTests for better coverage a…
arttonoyan e111714
test: Create OpenFeatureServiceCollectionExtensionsTests
arttonoyan cb63b1c
feat: Create OpenFeature.Hosting project
arttonoyan 0e53494
feat: Add HostedFeatureLifecycleService and related logic
arttonoyan dc765e6
test: Improve EnsureInitializedAsync_ShouldThrowException_WhenProvide…
arttonoyan 4f80593
add-dependency-injection
arttonoyan 0a76193
add-dependency-injection
arttonoyan ac98ddd
add-dependency-injection
arttonoyan 4af39ce
add-dependency-injection
arttonoyan 0fa6dc3
add-dependency-injection
arttonoyan 926c0d4
add-dependency-injection
arttonoyan 9b8d9f2
add-dependency-injection
arttonoyan aa488ae
feat: Replicate NoOpFeatureProvider implementation from src/OpenFeatu…
arttonoyan 1f8e9e4
add-dependency-injection
arttonoyan 3aaa7df
test: Improve EnsureInitializedAsync_ShouldThrowException_WhenProvide…
arttonoyan ffef1ac
add-dependency-injection
arttonoyan 1acb4fa
add-dependency-injection
arttonoyan 96889dd
Merge branch 'main' into add-dependency-injection
arttonoyan 54c145e
Fix dotnet format build.
askpt 55582d7
Changing to Source Generation logging.
askpt 8ebdad4
add-dependency-injection
arttonoyan 3089129
Merge branch 'add-dependency-injection' of https://github.com/arttono…
arttonoyan fe5e072
refactor: Update ThrowIfNull method
arttonoyan 10ea9f1
refactor: Change OpenFeatureBuilder to class and make IsContextConfig…
arttonoyan 3436db5
feat: Implement domain-scoped providers logic
arttonoyan 5738f3c
fix: Correct lines in package.props
arttonoyan 0ce727c
feat(core): Add DependencyInjection namespace for improved modularity
arttonoyan e8350d7
fix(build): Resolve build error in DependencyInjection namespace
arttonoyan eaf0319
feat(config): Add PolicyName logic to configure default FeatureClient
arttonoyan 7916d14
refactor(naming): Rename getClient to clientFactory for clarity
arttonoyan af78c5a
feat(policy): Implement PolicyName logic for enhanced configuration h…
arttonoyan 4fc100e
refactor: Make AddPolicyName extension method public
arttonoyan d536515
fix: Update AddPolicyName extension method to set IsPolicyConfigured …
arttonoyan 916f60a
feat(extensions): Add AddProvider extension method with default OpenF…
arttonoyan 387a88b
fix(tests): Resolve issues causing test failures
arttonoyan 4ac7f20
refactor(naming): Rename FeatureProviderBuilder to IFeatureProviderFa…
arttonoyan 17a66ca
fix(typo): Correct naming typo for improved readability
arttonoyan c424b2a
feat(validation): Add check for whitespace or empty values
arttonoyan 1de9096
feat(validation): Add check for whitespace or empty values
arttonoyan ca44115
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilder.cs
arttonoyan 3d33caa
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilder.cs
arttonoyan dfd66d1
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilderExtensio…
arttonoyan d169b0b
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilderExtensio…
arttonoyan ec6a81b
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilderExtensio…
arttonoyan a853b52
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilderExtensio…
arttonoyan 6849899
Update src/OpenFeature.DependencyInjection/OpenFeatureBuilderExtensio…
arttonoyan 73bb930
fix: Rename argument from name to domain
arttonoyan 749b18d
fix: Rename property to DomainBoundProviderRegistrationCount
arttonoyan f6e072d
refactor(namespaces): Move Guard class under DependencyInjection name…
arttonoyan b6a8e2d
feat: Create InMemoryProviderFactory and FeatureBuilderExtensions
arttonoyan ce56e84
Merge pull request #1 from arttonoyan/di-domain-scoped-providers
arttonoyan f1b8a9b
fix(formatting): Correct code formatting issues
arttonoyan 90481c0
Update src/OpenFeature.DependencyInjection/PolicyNameOptions.cs
arttonoyan 8252e47
Update src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs
arttonoyan 9704d2e
fix: Correct namespace issues
arttonoyan 124eb46
feat(diagnostics): Create Diagnostics namespace and add FeatureCodes
arttonoyan 5ea621b
feat(diagnostics): Add experimental attribute in selected classes
arttonoyan 0eceed8
chore(docs): Update summary for FeatureCodes
arttonoyan 6f8c5be
Merge pull request #3 from arttonoyan/feature/add-net8-experimental-a…
arttonoyan 547ba57
Update README.md
arttonoyan 462a4de
fix: Correct incorrect formats
arttonoyan f908bf5
Merge branch 'main' into add-dependency-injection
arttonoyan 02eccee
docs(OpenFeatureBuilderExtensions): Add exception details
arttonoyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
38 changes: 38 additions & 0 deletions
38
src/OpenFeature.DependencyInjection/Diagnostics/FeatureCodes.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace OpenFeature.DependencyInjection.Diagnostics; | ||
|
||
/// <summary> | ||
/// Contains identifiers for experimental features and diagnostics in the OpenFeature framework. | ||
/// </summary> | ||
/// <remarks> | ||
/// <c>Experimental</c> - This class includes identifiers that allow developers to track and conditionally enable | ||
/// experimental features. Each identifier follows a structured code format to indicate the feature domain, | ||
/// maturity level, and unique identifier. Note that experimental features are subject to change or removal | ||
/// in future releases. | ||
/// <para> | ||
/// <strong>Basic Information</strong><br/> | ||
/// These identifiers conform to OpenFeature’s Diagnostics Specifications, allowing developers to recognize | ||
/// and manage experimental features effectively. | ||
/// </para> | ||
/// </remarks> | ||
/// <example> | ||
/// <code> | ||
/// Code Structure: | ||
/// - "OF" - Represents the OpenFeature library. | ||
/// - "DI" - Indicates the Dependency Injection domain. | ||
/// - "001" - Unique identifier for a specific feature. | ||
/// </code> | ||
/// </example> | ||
internal static class FeatureCodes | ||
{ | ||
/// <summary> | ||
/// Identifier for the experimental Dependency Injection features within the OpenFeature framework. | ||
/// </summary> | ||
/// <remarks> | ||
/// <c>OFDI001</c> identifier marks experimental features in the Dependency Injection (DI) domain. | ||
/// | ||
/// Usage: | ||
/// Developers can use this identifier to conditionally enable or test experimental DI features. | ||
/// It is part of the OpenFeature diagnostics system to help track experimental functionality. | ||
/// </remarks> | ||
public const string NewDi = "OFDI001"; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace OpenFeature.DependencyInjection; | ||
|
||
[DebuggerStepThrough] | ||
internal static class Guard | ||
{ | ||
public static void ThrowIfNull(object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null) | ||
{ | ||
if (argument is null) | ||
throw new ArgumentNullException(paramName); | ||
} | ||
|
||
public static void ThrowIfNullOrWhiteSpace(string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null) | ||
{ | ||
if (string.IsNullOrWhiteSpace(argument)) | ||
throw new ArgumentNullException(paramName); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/OpenFeature.DependencyInjection/IFeatureLifecycleManager.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace OpenFeature.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Defines the contract for managing the lifecycle of a feature api. | ||
/// </summary> | ||
public interface IFeatureLifecycleManager | ||
{ | ||
/// <summary> | ||
/// Ensures that the feature provider is properly initialized and ready to be used. | ||
/// This method should handle all necessary checks, configuration, and setup required to prepare the feature provider. | ||
/// </summary> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns>A Task representing the asynchronous operation of initializing the feature provider.</returns> | ||
/// <exception cref="InvalidOperationException">Thrown when the feature provider is not registered or is in an invalid state.</exception> | ||
ValueTask EnsureInitializedAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Gracefully shuts down the feature api, ensuring all resources are properly disposed of and any persistent state is saved. | ||
/// This method should handle all necessary cleanup and shutdown operations for the feature provider. | ||
/// </summary> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns>A Task representing the asynchronous operation of shutting down the feature provider.</returns> | ||
ValueTask ShutdownAsync(CancellationToken cancellationToken = default); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/OpenFeature.DependencyInjection/IFeatureProviderFactory.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace OpenFeature.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Provides a contract for creating instances of <see cref="FeatureProvider"/>. | ||
/// This factory interface enables custom configuration and initialization of feature providers | ||
/// to support domain-specific or application-specific feature flag management. | ||
/// </summary> | ||
#if NET8_0_OR_GREATER | ||
[System.Diagnostics.CodeAnalysis.Experimental(Diagnostics.FeatureCodes.NewDi)] | ||
#endif | ||
public interface IFeatureProviderFactory | ||
{ | ||
/// <summary> | ||
/// Creates an instance of a <see cref="FeatureProvider"/> configured according to | ||
/// the specific settings implemented by the concrete factory. | ||
/// </summary> | ||
/// <returns> | ||
/// A new instance of <see cref="FeatureProvider"/>. | ||
/// The configuration and behavior of this provider instance are determined by | ||
/// the implementation of this method. | ||
/// </returns> | ||
FeatureProvider Create(); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/OpenFeature.DependencyInjection/Internal/FeatureLifecycleManager.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace OpenFeature.DependencyInjection.Internal; | ||
|
||
internal sealed partial class FeatureLifecycleManager : IFeatureLifecycleManager | ||
{ | ||
private readonly Api _featureApi; | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly ILogger<FeatureLifecycleManager> _logger; | ||
|
||
public FeatureLifecycleManager(Api featureApi, IServiceProvider serviceProvider, ILogger<FeatureLifecycleManager> logger) | ||
{ | ||
_featureApi = featureApi; | ||
_serviceProvider = serviceProvider; | ||
_logger = logger; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask EnsureInitializedAsync(CancellationToken cancellationToken = default) | ||
{ | ||
this.LogStartingInitializationOfFeatureProvider(); | ||
|
||
var options = _serviceProvider.GetRequiredService<IOptions<OpenFeatureOptions>>().Value; | ||
if (options.HasDefaultProvider) | ||
{ | ||
var featureProvider = _serviceProvider.GetRequiredService<FeatureProvider>(); | ||
await _featureApi.SetProviderAsync(featureProvider).ConfigureAwait(false); | ||
} | ||
|
||
foreach (var name in options.ProviderNames) | ||
{ | ||
var featureProvider = _serviceProvider.GetRequiredKeyedService<FeatureProvider>(name); | ||
await _featureApi.SetProviderAsync(name, featureProvider).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask ShutdownAsync(CancellationToken cancellationToken = default) | ||
{ | ||
this.LogShuttingDownFeatureProvider(); | ||
await _featureApi.ShutdownAsync().ConfigureAwait(false); | ||
} | ||
|
||
[LoggerMessage(200, LogLevel.Information, "Starting initialization of the feature provider")] | ||
partial void LogStartingInitializationOfFeatureProvider(); | ||
|
||
[LoggerMessage(200, LogLevel.Information, "Shutting down the feature provider")] | ||
partial void LogShuttingDownFeatureProvider(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/OpenFeature.DependencyInjection/MultiTarget/CallerArgumentExpressionAttribute.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @formatter:off | ||
// ReSharper disable All | ||
#if NETCOREAPP3_0_OR_GREATER | ||
// https://github.com/dotnet/runtime/issues/96197 | ||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.CallerArgumentExpressionAttribute))] | ||
#else | ||
#pragma warning disable | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] | ||
internal sealed class CallerArgumentExpressionAttribute : Attribute | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public CallerArgumentExpressionAttribute(string parameterName) | ||
{ | ||
ParameterName = parameterName; | ||
} | ||
|
||
public string ParameterName { get; } | ||
} | ||
#endif |
21 changes: 21 additions & 0 deletions
21
src/OpenFeature.DependencyInjection/MultiTarget/IsExternalInit.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @formatter:off | ||
// ReSharper disable All | ||
#if NET5_0_OR_GREATER | ||
// https://github.com/dotnet/runtime/issues/96197 | ||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))] | ||
#else | ||
#pragma warning disable | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ComponentModel; | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
/// <summary> | ||
/// Reserved to be used by the compiler for tracking metadata. | ||
/// This class should not be used by developers in source code. | ||
/// </summary> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
static class IsExternalInit { } | ||
#endif |
28 changes: 28 additions & 0 deletions
28
src/OpenFeature.DependencyInjection/OpenFeature.DependencyInjection.csproj
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net462</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>OpenFeature.DependencyInjection</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\OpenFeature\OpenFeature.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>$(AssemblyName).Tests</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace OpenFeature.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Describes a <see cref="OpenFeatureBuilder"/> backed by an <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="services">The services being configured.</param> | ||
public class OpenFeatureBuilder(IServiceCollection services) | ||
{ | ||
/// <summary> The services being configured. </summary> | ||
public IServiceCollection Services { get; } = services; | ||
|
||
/// <summary> | ||
/// Indicates whether the evaluation context has been configured. | ||
/// This property is used to determine if specific configurations or services | ||
/// should be initialized based on the presence of an evaluation context. | ||
/// </summary> | ||
public bool IsContextConfigured { get; internal set; } | ||
|
||
/// <summary> | ||
/// Indicates whether the policy has been configured. | ||
/// </summary> | ||
public bool IsPolicyConfigured { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether a default provider has been registered. | ||
/// </summary> | ||
public bool HasDefaultProvider { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the count of domain-bound providers that have been registered. | ||
/// This count does not include the default provider. | ||
/// </summary> | ||
public int DomainBoundProviderRegistrationCount { get; internal set; } | ||
|
||
/// <summary> | ||
/// Validates the current configuration, ensuring that a policy is set when multiple providers are registered | ||
/// or when a default provider is registered alongside another provider. | ||
/// </summary> | ||
/// <exception cref="InvalidOperationException"> | ||
/// Thrown if multiple providers are registered without a policy, or if both a default provider | ||
/// and an additional provider are registered without a policy configuration. | ||
/// </exception> | ||
public void Validate() | ||
{ | ||
if (!IsPolicyConfigured) | ||
{ | ||
if (DomainBoundProviderRegistrationCount > 1) | ||
{ | ||
throw new InvalidOperationException("Multiple providers have been registered, but no policy has been configured."); | ||
} | ||
|
||
if (HasDefaultProvider && DomainBoundProviderRegistrationCount == 1) | ||
{ | ||
throw new InvalidOperationException("A default provider and an additional provider have been registered without a policy configuration."); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
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.
This is a great addition.