Refactor ReCClient.Static to Create() method

Replaced the `ReCClient.Static` property with a `ReCClient.Create()` method to improve clarity and align with best practices. The new method retains the same functionality, including throwing an `InvalidOperationException` if the `Provider` is not built. The logic for retrieving the `IHttpClientFactory` and creating a `ReCClient` instance remains unchanged.
This commit is contained in:
Developer 02 2025-12-05 23:54:16 +01:00
parent 10fc56b262
commit 91c8b98f44

View File

@ -66,16 +66,13 @@ namespace ReC.Client
Provider = Services.BuildServiceProvider(); Provider = Services.BuildServiceProvider();
} }
public static ReCClient Static public static ReCClient Create()
{ {
get if (Provider == null)
{ throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
if (Provider == null)
throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
var httpClientFactory = Provider.GetRequiredService<IHttpClientFactory>(); var httpClientFactory = Provider.GetRequiredService<IHttpClientFactory>();
return new ReCClient(httpClientFactory); return new ReCClient(httpClientFactory);
}
} }
#endregion #endregion
} }