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();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user