diff --git a/src/Leanetec.EConnect.Client/DependencyInjection.cs b/src/Leanetec.EConnect.Client/DependencyInjection.cs index c29e4c5..4f2dcb0 100644 --- a/src/Leanetec.EConnect.Client/DependencyInjection.cs +++ b/src/Leanetec.EConnect.Client/DependencyInjection.cs @@ -1,13 +1,36 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Leanetec.EConnect.Client; public static class DependencyInjection { - public static IServiceCollection AddEConnectClient(this IServiceCollection services, Action clientOptions) + public static IServiceCollection AddEConnectClient(this IServiceCollection services, Action? options = null) { - services.Configure(clientOptions); + var config = new Config(services); + options?.Invoke(config); + services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly)); return services; } + + public sealed class Config + { + private readonly IServiceCollection _services; + + internal Config(IServiceCollection services) + { + _services = services; + } + + public void ConfigureClient(IConfiguration config) + { + _services.Configure(config); + } + + public void ConfigureClient(Action options) + { + _services.Configure(options); + } + } } \ No newline at end of file diff --git a/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj b/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj index ee85239..25cf8b3 100644 --- a/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj +++ b/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj @@ -8,6 +8,8 @@ + + diff --git a/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs b/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs index 9888b3e..1fb504a 100644 --- a/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs +++ b/src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs @@ -27,10 +27,10 @@ public static class DependencyInjection return services; } - public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action options) + public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action? options = null) { Config config = new(services); - options.Invoke(config); + options?.Invoke(config); services.ConfigureEConnectClient(config.EConnectClient); services.AddScoped(typeof(IEConnectClient<>), typeof(EConnectClient<>)); return services; diff --git a/src/Leanetec.EConnect.Proxy/Program.cs b/src/Leanetec.EConnect.Proxy/Program.cs index c8d0769..8eda0c7 100644 --- a/src/Leanetec.EConnect.Proxy/Program.cs +++ b/src/Leanetec.EConnect.Proxy/Program.cs @@ -2,9 +2,11 @@ using Leanetec.EConnect.Client; using Leanetec.EConnect.Infrastructure; var builder = WebApplication.CreateBuilder(args); +var config = builder.Configuration; // Add services to the container. -builder.Services.AddEConnectClient(opt => { }).AddInfrastructureServices(opt => { }); +var clientOpt = config.GetSection("EConnect"); +builder.Services.AddEConnectClient(opt => opt.ConfigureClient(clientOpt)).AddInfrastructureServices(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/src/Leanetec.EConnect.Proxy/appsettings.json b/src/Leanetec.EConnect.Proxy/appsettings.json index 10f68b8..56a2220 100644 --- a/src/Leanetec.EConnect.Proxy/appsettings.json +++ b/src/Leanetec.EConnect.Proxy/appsettings.json @@ -5,5 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "EConnect": { + "BaseAddress": "https://portal.demoportal01.leanetec.com", + "apiKey": "HGpGp3vk3MsKgSe0tKVZ1ZRCuq6bFoJ1" + } }