// 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 {{ if .Params.Custom.Namespace }}{{ .Params.Custom.Namespace }}{{ else }}OpenFeatureGenerated{{ end }} { /// /// 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)); } {{- range .Flagset.Flags }} /// /// {{ .Description }} /// /// /// Flag key: {{ .Key }} /// Default value: {{ if eq (.Type | OpenFeatureType) "object" }}{{ .DefaultValue | ToCSharpDict }}{{ else }}{{ .DefaultValue }}{{ end }} /// Type: {{ .Type | OpenFeatureType }} /// /// Optional context for the flag evaluation /// Options for flag evaluation /// The flag value public async Task<{{ if eq (.Type | OpenFeatureType) "object" }}Value{{ else }}{{ .Type | OpenFeatureType }}{{ end }}> {{ .Key | ToPascal }}Async(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null) { {{- if eq .Type 1 }} return await _client.GetIntegerValueAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 2 }} return await _client.GetDoubleValueAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 3 }} return await _client.GetBooleanValueAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 4 }} return await _client.GetStringValueAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 5 }} return await _client.GetObjectValueAsync("{{ .Key }}", {{ if eq (.Type | OpenFeatureType) "object" }}{{ .DefaultValue | ToCSharpDict }}{{ else }}{{ . | FormatDefaultValue }}{{ end }}, evaluationContext, options); {{- else }} throw new NotSupportedException("Unsupported flag type"); {{- end }} } /// /// {{ .Description }} /// /// /// Flag key: {{ .Key }} /// Default value: {{ if eq (.Type | OpenFeatureType) "object" }}{{ .DefaultValue | ToCSharpDict }}{{ else }}{{ .DefaultValue }}{{ end }} /// Type: {{ .Type | OpenFeatureType }} /// /// Optional context for the flag evaluation /// Options for flag evaluation /// The evaluation details containing the flag value and metadata public async Task> {{ .Key | ToPascal }}DetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null) { {{- if eq .Type 1 }} return await _client.GetIntegerDetailsAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 2 }} return await _client.GetDoubleDetailsAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 3 }} return await _client.GetBooleanDetailsAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 4 }} return await _client.GetStringDetailsAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options); {{- else if eq .Type 5 }} return await _client.GetObjectDetailsAsync("{{ .Key }}", {{ if eq (.Type | OpenFeatureType) "object" }}{{ .DefaultValue | ToCSharpDict }}{{ else }}{{ . | FormatDefaultValue }}{{ end }}, evaluationContext, options); {{- else }} throw new NotSupportedException("Unsupported flag type"); {{- end }} } {{ end }} /// /// 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)); } } }