Refactor: Rename ServiceProvider to Provider

Renamed the static field `ServiceProvider` to `Provider` across
the `ReC.Client` namespace in `ReCClient.cs` for consistency
and clarity. Updated all occurrences, including declarations,
usages, and exception messages. Adjusted conditional compilation
blocks to reflect the new name. Ensured the `BuildStaticClient`
method and `Static` property use the renamed field appropriately.
This commit is contained in:
Developer 02
2025-12-05 23:52:25 +01:00
parent 71368e5c85
commit 10fc56b262

View File

@@ -49,31 +49,31 @@ namespace ReC.Client
private static readonly IServiceCollection Services = new ServiceCollection(); private static readonly IServiceCollection Services = new ServiceCollection();
#if NET8_0_OR_GREATER #if NET8_0_OR_GREATER
private static IServiceProvider? ServiceProvider = null; private static IServiceProvider? Provider = null;
#else #else
private static IServiceProvider ServiceProvider = null; private static IServiceProvider Provider = null;
#endif #endif
public static void BuildStaticClient(string apiUri) public static void BuildStaticClient(string apiUri)
{ {
if(ServiceProvider != null) if(Provider != null)
throw new InvalidOperationException("Static ServiceProvider is already built."); throw new InvalidOperationException("Static Provider is already built.");
Services.AddHttpClient(ClientName, client => Services.AddHttpClient(ClientName, client =>
{ {
client.BaseAddress = new Uri(apiUri); client.BaseAddress = new Uri(apiUri);
}); });
ServiceProvider = Services.BuildServiceProvider(); Provider = Services.BuildServiceProvider();
} }
public static ReCClient Static public static ReCClient Static
{ {
get get
{ {
if (ServiceProvider == null) if (Provider == null)
throw new InvalidOperationException("Static ServiceProvider is not built. Call BuildStaticClient first."); throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
var httpClientFactory = ServiceProvider.GetRequiredService<IHttpClientFactory>(); var httpClientFactory = Provider.GetRequiredService<IHttpClientFactory>();
return new ReCClient(httpClientFactory); return new ReCClient(httpClientFactory);
} }
} }