diff --git a/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs b/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs new file mode 100644 index 0000000..590ecb2 --- /dev/null +++ b/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Leanetec.EConnect.Infrastructure; + +public static class DependencyInjection +{ + internal static readonly string HttpClientName = Guid.NewGuid().ToString(); + + internal static IServiceCollection ConfigureHttpClient(this IServiceCollection services, Action configureClient) + { + services.AddHttpClient(HttpClientName, configureClient); + return services; + } + + public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action options) + { + Config config = new(services); + options.Invoke(config); + services.ConfigureHttpClient(config.Client); + return services; + } + + public sealed class Config + { + private readonly IServiceCollection _services; + + internal Config(IServiceCollection services) + { + _services = services; + } + + public Action Client { get; set; } = _ => { }; + } +} diff --git a/src/Leanetec.EConnect.Infrastructure/Leanetec.EConnect.Infrastructure.csproj b/src/Leanetec.EConnect.Infrastructure/Leanetec.EConnect.Infrastructure.csproj index fa71b7a..b51938e 100644 --- a/src/Leanetec.EConnect.Infrastructure/Leanetec.EConnect.Infrastructure.csproj +++ b/src/Leanetec.EConnect.Infrastructure/Leanetec.EConnect.Infrastructure.csproj @@ -6,4 +6,9 @@ enable + + + + +