-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: register services only if feature flags are enabled
- Loading branch information
Showing
3 changed files
with
35 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Fracture.Server.Modules.AI.Services; | ||
using Fracture.Server.Modules.Shared.Configuration; | ||
using Microsoft.FeatureManagement; | ||
|
||
namespace Fracture.Server.Modules.Shared | ||
{ | ||
public static class BuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds to services elements only if there is a proper feature flag enabled in the configuration | ||
/// </summary> | ||
public static async Task AddFeatureGatedServices(this IServiceCollection services) | ||
{ | ||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
var featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider( | ||
configuration.GetSection(FeatureFlags.CONFIG_SECTION) | ||
); | ||
var featureManager = new FeatureManager(featureDefinitionProvider); | ||
|
||
if (await featureManager.IsEnabledAsync(FeatureFlags.USE_AI)) | ||
services.AddSingleton< | ||
IAIInstructionProvider, | ||
OpenAICompatibleInstructionProvider | ||
>(); | ||
} | ||
} | ||
} |
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