mirror of https://github.com/open-feature/cli.git
251 lines
12 KiB
C#
251 lines
12 KiB
C#
// 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
|
|
{
|
|
/// <summary>
|
|
/// Service collection extensions for OpenFeature
|
|
/// </summary>
|
|
public static class OpenFeatureServiceExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds OpenFeature services to the service collection with the generated client
|
|
/// </summary>
|
|
/// <param name="services">The service collection to add services to</param>
|
|
/// <returns>The service collection for chaining</returns>
|
|
public static IServiceCollection AddOpenFeature(this IServiceCollection services)
|
|
{
|
|
return services
|
|
.AddSingleton(_ => Api.Instance)
|
|
.AddSingleton(provider => provider.GetRequiredService<Api>().GetClient())
|
|
.AddSingleton<GeneratedClient>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds OpenFeature services to the service collection with the generated client for a specific domain
|
|
/// </summary>
|
|
/// <param name="services">The service collection to add services to</param>
|
|
/// <param name="domain">The domain to get the client for</param>
|
|
/// <returns>The service collection for chaining</returns>
|
|
public static IServiceCollection AddOpenFeature(this IServiceCollection services, string domain)
|
|
{
|
|
return services
|
|
.AddSingleton(_ => Api.Instance)
|
|
.AddSingleton(provider => provider.GetRequiredService<Api>().GetClient(domain))
|
|
.AddSingleton<GeneratedClient>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generated OpenFeature client for typesafe flag access
|
|
/// </summary>
|
|
public class GeneratedClient
|
|
{
|
|
private readonly IFeatureClient _client;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="GeneratedClient"/> class.
|
|
/// </summary>
|
|
/// <param name="client">The OpenFeature client to use for flag evaluations.</param>
|
|
public GeneratedClient(IFeatureClient client)
|
|
{
|
|
_client = client ?? throw new ArgumentNullException(nameof(client));
|
|
}
|
|
/// <summary>
|
|
/// Discount percentage applied to purchases.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: discountPercentage</para>
|
|
/// <para>Default value: 0.15</para>
|
|
/// <para>Type: double</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The flag value</returns>
|
|
public async Task<double> DiscountPercentageAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetDoubleValueAsync("discountPercentage", 0.15, evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Discount percentage applied to purchases.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: discountPercentage</para>
|
|
/// <para>Default value: 0.15</para>
|
|
/// <para>Type: double</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The evaluation details containing the flag value and metadata</returns>
|
|
public async Task<FlagEvaluationDetails<double>> DiscountPercentageDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetDoubleDetailsAsync("discountPercentage", 0.15, evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Controls whether Feature A is enabled.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: enableFeatureA</para>
|
|
/// <para>Default value: false</para>
|
|
/// <para>Type: bool</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The flag value</returns>
|
|
public async Task<bool> EnableFeatureAAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetBooleanValueAsync("enableFeatureA", false, evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Controls whether Feature A is enabled.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: enableFeatureA</para>
|
|
/// <para>Default value: false</para>
|
|
/// <para>Type: bool</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The evaluation details containing the flag value and metadata</returns>
|
|
public async Task<FlagEvaluationDetails<bool>> EnableFeatureADetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetBooleanDetailsAsync("enableFeatureA", false, evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The message to use for greeting users.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: greetingMessage</para>
|
|
/// <para>Default value: Hello there!</para>
|
|
/// <para>Type: string</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The flag value</returns>
|
|
public async Task<string> GreetingMessageAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetStringValueAsync("greetingMessage", "Hello there!", evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The message to use for greeting users.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: greetingMessage</para>
|
|
/// <para>Default value: Hello there!</para>
|
|
/// <para>Type: string</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The evaluation details containing the flag value and metadata</returns>
|
|
public async Task<FlagEvaluationDetails<string>> GreetingMessageDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetStringDetailsAsync("greetingMessage", "Hello there!", evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Allows customization of theme colors.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: themeCustomization</para>
|
|
/// <para>Default value: new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())</para>
|
|
/// <para>Type: object</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The flag value</returns>
|
|
public async Task<Value> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Allows customization of theme colors.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: themeCustomization</para>
|
|
/// <para>Default value: new Value(Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())</para>
|
|
/// <para>Type: object</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The evaluation details containing the flag value and metadata</returns>
|
|
public async Task<FlagEvaluationDetails<Value>> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maximum allowed length for usernames.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: usernameMaxLength</para>
|
|
/// <para>Default value: 50</para>
|
|
/// <para>Type: int</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The flag value</returns>
|
|
public async Task<int> UsernameMaxLengthAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetIntegerValueAsync("usernameMaxLength", 50, evaluationContext, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maximum allowed length for usernames.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>Flag key: usernameMaxLength</para>
|
|
/// <para>Default value: 50</para>
|
|
/// <para>Type: int</para>
|
|
/// </remarks>
|
|
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
|
|
/// <param name="options">Options for flag evaluation</param>
|
|
/// <returns>The evaluation details containing the flag value and metadata</returns>
|
|
public async Task<FlagEvaluationDetails<int>> UsernameMaxLengthDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
|
|
{
|
|
return await _client.GetIntegerDetailsAsync("usernameMaxLength", 50, evaluationContext, options);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Creates a new GeneratedClient using the default OpenFeature client
|
|
/// </summary>
|
|
/// <returns>A new GeneratedClient instance</returns>
|
|
public static GeneratedClient CreateClient()
|
|
{
|
|
return new GeneratedClient(Api.Instance.GetClient());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new GeneratedClient using a domain-specific OpenFeature client
|
|
/// </summary>
|
|
/// <param name="domain">The domain to get the client for</param>
|
|
/// <returns>A new GeneratedClient instance</returns>
|
|
public static GeneratedClient CreateClient(string domain)
|
|
{
|
|
return new GeneratedClient(Api.Instance.GetClient(domain));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new GeneratedClient using a domain-specific OpenFeature client with context
|
|
/// </summary>
|
|
/// <param name="domain">The domain to get the client for</param>
|
|
/// <param name="evaluationContext">Default context to use for evaluations</param>
|
|
/// <returns>A new GeneratedClient instance</returns>
|
|
public static GeneratedClient CreateClient(string domain, EvaluationContext? evaluationContext = null)
|
|
{
|
|
return new GeneratedClient(Api.Instance.GetClient(domain));
|
|
}
|
|
}
|
|
} |