diff --git a/src/OpenFeature/Api.cs b/src/OpenFeature/Api.cs
index fae9916b..bc0499dd 100644
--- a/src/OpenFeature/Api.cs
+++ b/src/OpenFeature/Api.cs
@@ -29,7 +29,7 @@ public sealed class Api : IEventBus
///
/// Singleton instance of Api
///
- public static Api Instance { get; } = new Api();
+ public static Api Instance { get; private set; } = new Api();
// Explicit static constructor to tell C# compiler
// not to mark type as beforeFieldInit
@@ -300,5 +300,13 @@ private async Task AfterError(FeatureProvider provider, Exception? ex)
await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
}
+
+ ///
+ /// This method should only be using for testing purposes. It will reset the singleton instance of the API.
+ ///
+ internal static void ResetApi()
+ {
+ Instance = new Api();
+ }
}
}
diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
index 5a620214..c3351801 100644
--- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
+++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
@@ -1,14 +1,20 @@
-using System;
+using System.Threading.Tasks;
+using Xunit;
namespace OpenFeature.Tests;
-public class ClearOpenFeatureInstanceFixture : IDisposable
+public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
{
+ public Task InitializeAsync()
+ {
+ Api.ResetApi();
+
+ return Task.CompletedTask;
+ }
+
// Make sure the singleton is cleared between tests
- public void Dispose()
+ public async Task DisposeAsync()
{
- Api.Instance.SetContext(null);
- Api.Instance.ClearHooks();
- Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
+ await Api.Instance.ShutdownAsync().ConfigureAwait(false);
}
}