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:
@@ -49,31 +49,31 @@ namespace ReC.Client
|
||||
private static readonly IServiceCollection Services = new ServiceCollection();
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
private static IServiceProvider? ServiceProvider = null;
|
||||
private static IServiceProvider? Provider = null;
|
||||
#else
|
||||
private static IServiceProvider ServiceProvider = null;
|
||||
private static IServiceProvider Provider = null;
|
||||
#endif
|
||||
|
||||
public static void BuildStaticClient(string apiUri)
|
||||
{
|
||||
if(ServiceProvider != null)
|
||||
throw new InvalidOperationException("Static ServiceProvider is already built.");
|
||||
if(Provider != null)
|
||||
throw new InvalidOperationException("Static Provider is already built.");
|
||||
|
||||
Services.AddHttpClient(ClientName, client =>
|
||||
{
|
||||
client.BaseAddress = new Uri(apiUri);
|
||||
});
|
||||
ServiceProvider = Services.BuildServiceProvider();
|
||||
Provider = Services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public static ReCClient Static
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ServiceProvider == null)
|
||||
throw new InvalidOperationException("Static ServiceProvider is not built. Call BuildStaticClient first.");
|
||||
if (Provider == null)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user