Skip to content

Commit 3b609ad

Browse files
committed
Add HostedFeatureLifecycleService when AddOpenFeature is called
* Update Samples App to show how you can work with OpenFeature and Dependency Injection Signed-off-by: Kyle Julian <[email protected]>
1 parent 225b58d commit 3b609ad

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

samples/AspNetCore/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
.WithFlagEvaluationMetadata("boolean", s => s.GetBool("boolean"))
3232
.Build();
3333

34-
featureBuilder.AddHostedFeatureLifecycle()
34+
featureBuilder
3535
.AddHook(sp => new LoggingHook(sp.GetRequiredService<ILogger<LoggingHook>>()))
3636
.AddHook(_ => new MetricsHook(metricsHookOptions))
3737
.AddHook<TraceEnricherHook>()

samples/AspNetCore/Samples.AspNetCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\..\src\OpenFeature.DependencyInjection\OpenFeature.DependencyInjection.csproj" />
98
<ProjectReference Include="..\..\src\OpenFeature.Hosting\OpenFeature.Hosting.csproj" />
109
<ProjectReference Include="..\..\src\OpenFeature\OpenFeature.csproj" />
1110
</ItemGroup>

src/OpenFeature.Hosting/DependencyInjection/OpenFeatureServiceCollectionExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Extensions.Options;
44
using OpenFeature.DependencyInjection;
55
using OpenFeature.DependencyInjection.Internal;
6+
using OpenFeature.Hosting;
67

78
namespace OpenFeature;
89

@@ -54,6 +55,9 @@ public static IServiceCollection AddOpenFeature(this IServiceCollection services
5455
}
5556

5657
builder.AddPolicyBasedClient();
58+
59+
builder.Services.AddHostedService<HostedFeatureLifecycleService>();
60+
5761
return services;
5862
}
5963
}

src/OpenFeature.Hosting/OpenFeatureBuilderExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static partial class OpenFeatureBuilderExtensions
1717
/// <param name="builder">The <see cref="OpenFeatureBuilder"/> instance.</param>
1818
/// <param name="configureOptions">An optional action to configure <see cref="FeatureLifecycleStateOptions"/>.</param>
1919
/// <returns>The <see cref="OpenFeatureBuilder"/> instance.</returns>
20+
[Obsolete("Calling AddHostedFeatureLifecycle() is no longer necessary. OpenFeature will inject this automatically when you call AddOpenFeature().")]
2021
public static OpenFeatureBuilder AddHostedFeatureLifecycle(this OpenFeatureBuilder builder, Action<FeatureLifecycleStateOptions>? configureOptions = null)
2122
{
2223
if (configureOptions is not null)

0 commit comments

Comments
 (0)