Add DependencyInjection support for ReCClient
Introduced a `DependencyInjection` class in the `ReC.Client` namespace to enable dependency injection for `ReCClient`. Added an `AddRecClient` extension method for `IServiceCollection` to register an `HttpClient` with a configurable `apiUri` as the base address. Included conditional `using System;` for .NET Framework compatibility and added `Microsoft.Extensions.DependencyInjection` to support DI services.
This commit is contained in:
parent
4ee79d6cd8
commit
8cad1df95d
18
src/ReC.Client/DependencyInjection.cs
Normal file
18
src/ReC.Client/DependencyInjection.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ReC.Client
|
||||||
|
{
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri)
|
||||||
|
{
|
||||||
|
return services.AddHttpClient(ReCClient.ClientName, client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri(apiUri);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user