4
4
using System . Threading ;
5
5
using System . Threading . Tasks ;
6
6
using Microsoft . Extensions . Logging ;
7
+ using OpenFeature . Constant ;
7
8
using OpenFeature . Model ;
8
9
9
10
namespace OpenFeature
@@ -13,7 +14,7 @@ namespace OpenFeature
13
14
/// In the absence of a provider the evaluation API uses the "No-op provider", which simply returns the supplied default flag value.
14
15
/// </summary>
15
16
/// <seealso href="https://github.com/open-feature/spec/blob/v0.5.2/specification/sections/01-flag-evaluation.md#1-flag-evaluation-api"/>
16
- public sealed class Api
17
+ public sealed class Api : IEventBus
17
18
{
18
19
private EvaluationContext _evaluationContext = EvaluationContext . Empty ;
19
20
private readonly ProviderRepository _repository = new ProviderRepository ( ) ;
@@ -22,6 +23,8 @@ public sealed class Api
22
23
/// The reader/writer locks are not disposed because the singleton instance should never be disposed.
23
24
private readonly ReaderWriterLockSlim _evaluationContextLock = new ReaderWriterLockSlim ( ) ;
24
25
26
+ internal readonly EventExecutor EventExecutor = new EventExecutor ( ) ;
27
+
25
28
26
29
/// <summary>
27
30
/// Singleton instance of Api
@@ -42,6 +45,7 @@ private Api() { }
42
45
/// <param name="featureProvider">Implementation of <see cref="FeatureProvider"/></param>
43
46
public async Task SetProvider ( FeatureProvider featureProvider )
44
47
{
48
+ this . EventExecutor . RegisterDefaultFeatureProvider ( featureProvider ) ;
45
49
await this . _repository . SetProvider ( featureProvider , this . GetContext ( ) ) . ConfigureAwait ( false ) ;
46
50
}
47
51
@@ -54,6 +58,7 @@ public async Task SetProvider(FeatureProvider featureProvider)
54
58
/// <param name="featureProvider">Implementation of <see cref="FeatureProvider"/></param>
55
59
public async Task SetProvider ( string clientName , FeatureProvider featureProvider )
56
60
{
61
+ this . EventExecutor . RegisterClientFeatureProvider ( clientName , featureProvider ) ;
57
62
await this . _repository . SetProvider ( clientName , featureProvider , this . GetContext ( ) ) . ConfigureAwait ( false ) ;
58
63
}
59
64
@@ -201,6 +206,28 @@ public EvaluationContext GetContext()
201
206
public async Task Shutdown ( )
202
207
{
203
208
await this . _repository . Shutdown ( ) . ConfigureAwait ( false ) ;
209
+ await this . EventExecutor . Shutdown ( ) . ConfigureAwait ( false ) ;
210
+ }
211
+
212
+ /// <inheritdoc />
213
+ public void AddHandler ( ProviderEventTypes type , EventHandlerDelegate handler )
214
+ {
215
+ this . EventExecutor . AddApiLevelHandler ( type , handler ) ;
216
+ }
217
+
218
+ /// <inheritdoc />
219
+ public void RemoveHandler ( ProviderEventTypes type , EventHandlerDelegate handler )
220
+ {
221
+ this . EventExecutor . RemoveApiLevelHandler ( type , handler ) ;
222
+ }
223
+
224
+ /// <summary>
225
+ /// Sets the logger for the API
226
+ /// </summary>
227
+ /// <param name="logger">The logger to be used</param>
228
+ public void SetLogger ( ILogger logger )
229
+ {
230
+ this . EventExecutor . Logger = logger ;
204
231
}
205
232
}
206
233
}
0 commit comments