forked from open-feature/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenFeature.g.cs
More file actions
252 lines (235 loc) · 11.8 KB
/
OpenFeature.g.cs
File metadata and controls
252 lines (235 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// AUTOMATICALLY GENERATED BY OPENFEATURE CLI, DO NOT EDIT.
#nullable enable
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));
}
}
}