@@ -18,6 +18,7 @@ public sealed partial class FeatureClient : IFeatureClient
18
18
private readonly ConcurrentStack < Hook > _hooks = new ConcurrentStack < Hook > ( ) ;
19
19
private readonly ILogger _logger ;
20
20
private readonly Func < FeatureProvider > _providerAccessor ;
21
+ private readonly Api _api ;
21
22
private EvaluationContext _evaluationContext ;
22
23
23
24
private readonly object _evaluationContextLock = new object ( ) ;
@@ -40,7 +41,7 @@ public sealed partial class FeatureClient : IFeatureClient
40
41
{
41
42
// Alias the provider reference so getting the method and returning the provider are
42
43
// guaranteed to be the same object.
43
- var provider = Api . Instance . GetProvider ( this . _metadata . Name ! ) ;
44
+ var provider = this . _api . GetProvider ( this . _metadata . Name ! ) ;
44
45
45
46
return ( method ( provider ) , provider ) ;
46
47
}
@@ -69,18 +70,20 @@ public void SetContext(EvaluationContext? context)
69
70
/// <summary>
70
71
/// Initializes a new instance of the <see cref="FeatureClient"/> class.
71
72
/// </summary>
73
+ /// <param name="api">The API instance for accessing global state and providers</param>
72
74
/// <param name="providerAccessor">Function to retrieve current provider</param>
73
75
/// <param name="name">Name of client <see cref="ClientMetadata"/></param>
74
76
/// <param name="version">Version of client <see cref="ClientMetadata"/></param>
75
77
/// <param name="logger">Logger used by client</param>
76
78
/// <param name="context">Context given to this client</param>
77
79
/// <exception cref="ArgumentNullException">Throws if any of the required parameters are null</exception>
78
- internal FeatureClient ( Func < FeatureProvider > providerAccessor , string ? name , string ? version , ILogger ? logger = null , EvaluationContext ? context = null )
80
+ internal FeatureClient ( Api api , Func < FeatureProvider > providerAccessor , string ? name , string ? version , ILogger ? logger = null , EvaluationContext ? context = null )
79
81
{
82
+ this . _api = api ;
83
+ this . _providerAccessor = providerAccessor ;
80
84
this . _metadata = new ClientMetadata ( name , version ) ;
81
85
this . _logger = logger ?? NullLogger < FeatureClient > . Instance ;
82
86
this . _evaluationContext = context ?? EvaluationContext . Empty ;
83
- this . _providerAccessor = providerAccessor ;
84
87
}
85
88
86
89
/// <inheritdoc />
@@ -99,13 +102,13 @@ internal FeatureClient(Func<FeatureProvider> providerAccessor, string? name, str
99
102
/// <inheritdoc />
100
103
public void AddHandler ( ProviderEventTypes eventType , EventHandlerDelegate handler )
101
104
{
102
- Api . Instance . AddClientHandler ( this . _metadata . Name ! , eventType , handler ) ;
105
+ this . _api . AddClientHandler ( this . _metadata . Name ! , eventType , handler ) ;
103
106
}
104
107
105
108
/// <inheritdoc />
106
109
public void RemoveHandler ( ProviderEventTypes type , EventHandlerDelegate handler )
107
110
{
108
- Api . Instance . RemoveClientHandler ( this . _metadata . Name ! , type , handler ) ;
111
+ this . _api . RemoveClientHandler ( this . _metadata . Name ! , type , handler ) ;
109
112
}
110
113
111
114
/// <inheritdoc />
@@ -213,13 +216,13 @@ private async Task<FlagEvaluationDetails<T>> EvaluateFlagAsync<T>(
213
216
214
217
// merge api, client, transaction and invocation context
215
218
var evaluationContextBuilder = EvaluationContext . Builder ( ) ;
216
- evaluationContextBuilder . Merge ( Api . Instance . GetContext ( ) ) ; // API context
219
+ evaluationContextBuilder . Merge ( this . _api . GetContext ( ) ) ; // API context
217
220
evaluationContextBuilder . Merge ( this . GetContext ( ) ) ; // Client context
218
- evaluationContextBuilder . Merge ( Api . Instance . GetTransactionContext ( ) ) ; // Transaction context
221
+ evaluationContextBuilder . Merge ( this . _api . GetTransactionContext ( ) ) ; // Transaction context
219
222
evaluationContextBuilder . Merge ( context ) ; // Invocation context
220
223
221
224
var allHooks = ImmutableList . CreateBuilder < Hook > ( )
222
- . Concat ( Api . Instance . GetHooks ( ) )
225
+ . Concat ( this . _api . GetHooks ( ) )
223
226
. Concat ( this . GetHooks ( ) )
224
227
. Concat ( options ? . Hooks ?? Enumerable . Empty < Hook > ( ) )
225
228
. Concat ( provider . GetProviderHooks ( ) )
@@ -310,7 +313,7 @@ public void Track(string trackingEventName, EvaluationContext? evaluationContext
310
313
throw new ArgumentException ( "Tracking event cannot be null or empty." , nameof ( trackingEventName ) ) ;
311
314
}
312
315
313
- var globalContext = Api . Instance . GetContext ( ) ;
316
+ var globalContext = this . _api . GetContext ( ) ;
314
317
var clientContext = this . GetContext ( ) ;
315
318
316
319
var evaluationContextBuilder = EvaluationContext . Builder ( )
0 commit comments