// AUTOMATICALLY GENERATED BY OPENFEATURE CLI, DO NOT EDIT.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using OpenFeature;
using OpenFeature.Model;
namespace TestNamespace
{
///
/// Service collection extensions for OpenFeature
///
public static class OpenFeatureServiceExtensions
{
///
/// Adds OpenFeature services to the service collection with the generated client
///
/// The service collection to add services to
/// The service collection for chaining
public static IServiceCollection AddOpenFeature(this IServiceCollection services)
{
return services
.AddSingleton(_ => Api.Instance)
.AddSingleton(provider => provider.GetRequiredService().GetClient())
.AddSingleton();
}
///
/// Adds OpenFeature services to the service collection with the generated client for a specific domain
///
/// The service collection to add services to
/// The domain to get the client for
/// The service collection for chaining
public static IServiceCollection AddOpenFeature(this IServiceCollection services, string domain)
{
return services
.AddSingleton(_ => Api.Instance)
.AddSingleton(provider => provider.GetRequiredService().GetClient(domain))
.AddSingleton();
}
}
///
/// Generated OpenFeature client for typesafe flag access
///
public class GeneratedClient
{
private readonly IFeatureClient _client;
///
/// Initializes a new instance of the class.
///
/// The OpenFeature client to use for flag evaluations.
public GeneratedClient(IFeatureClient client)
{
_client = client ?? throw new ArgumentNullException(nameof(client));
}
///
/// Discount percentage applied to purchases.
///
///
/// Flag key: discountPercentage
/// Default value: 0.15
/// Type: double
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The flag value
public async Task DiscountPercentageAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetDoubleValueAsync("discountPercentage", 0.15, evaluationContext, options);
}
///
/// Discount percentage applied to purchases.
///
///
/// Flag key: discountPercentage
/// Default value: 0.15
/// Type: double
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The evaluation details containing the flag value and metadata
public async Task> DiscountPercentageDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetDoubleDetailsAsync("discountPercentage", 0.15, evaluationContext, options);
}
///
/// Controls whether Feature A is enabled.
///
///
/// Flag key: enableFeatureA
/// Default value: false
/// Type: bool
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The flag value
public async Task EnableFeatureAAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetBooleanValueAsync("enableFeatureA", false, evaluationContext, options);
}
///
/// Controls whether Feature A is enabled.
///
///
/// Flag key: enableFeatureA
/// Default value: false
/// Type: bool
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The evaluation details containing the flag value and metadata
public async Task> EnableFeatureADetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetBooleanDetailsAsync("enableFeatureA", false, evaluationContext, options);
}
///
/// The message to use for greeting users.
///
///
/// Flag key: greetingMessage
/// Default value: Hello there!
/// Type: string
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The flag value
public async Task GreetingMessageAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetStringValueAsync("greetingMessage", "Hello there!", evaluationContext, options);
}
///
/// The message to use for greeting users.
///
///
/// Flag key: greetingMessage
/// Default value: Hello there!
/// Type: string
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The evaluation details containing the flag value and metadata
public async Task> GreetingMessageDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetStringDetailsAsync("greetingMessage", "Hello there!", evaluationContext, options);
}
///
/// Allows customization of theme colors.
///
///
/// Flag key: themeCustomization
/// Default value: new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())
/// Type: object
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The flag value
public async Task ThemeCustomizationAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetObjectValueAsync("themeCustomization", new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build()), evaluationContext, options);
}
///
/// Allows customization of theme colors.
///
///
/// Flag key: themeCustomization
/// Default value: new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())
/// Type: object
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The evaluation details containing the flag value and metadata
public async Task> ThemeCustomizationDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetObjectDetailsAsync("themeCustomization", new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build()), evaluationContext, options);
}
///
/// Maximum allowed length for usernames.
///
///
/// Flag key: usernameMaxLength
/// Default value: 50
/// Type: int
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The flag value
public async Task UsernameMaxLengthAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetIntegerValueAsync("usernameMaxLength", 50, evaluationContext, options);
}
///
/// Maximum allowed length for usernames.
///
///
/// Flag key: usernameMaxLength
/// Default value: 50
/// Type: int
///
/// Optional context for the flag evaluation
/// Options for flag evaluation
/// The evaluation details containing the flag value and metadata
public async Task> UsernameMaxLengthDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetIntegerDetailsAsync("usernameMaxLength", 50, evaluationContext, options);
}
///
/// Creates a new GeneratedClient using the default OpenFeature client
///
/// A new GeneratedClient instance
public static GeneratedClient CreateClient()
{
return new GeneratedClient(Api.Instance.GetClient());
}
///
/// Creates a new GeneratedClient using a domain-specific OpenFeature client
///
/// The domain to get the client for
/// A new GeneratedClient instance
public static GeneratedClient CreateClient(string domain)
{
return new GeneratedClient(Api.Instance.GetClient(domain));
}
///
/// Creates a new GeneratedClient using a domain-specific OpenFeature client with context
///
/// The domain to get the client for
/// Default context to use for evaluations
/// A new GeneratedClient instance
public static GeneratedClient CreateClient(string domain, EvaluationContext? evaluationContext = null)
{
return new GeneratedClient(Api.Instance.GetClient(domain));
}
}
}