diff --git a/src/JustCSharp.ShopeeSDK/Extensions/ServiceCollectionExtensions.cs b/src/JustCSharp.ShopeeSDK/Extensions/ServiceCollectionExtensions.cs index c928cf7..d4340b3 100644 --- a/src/JustCSharp.ShopeeSDK/Extensions/ServiceCollectionExtensions.cs +++ b/src/JustCSharp.ShopeeSDK/Extensions/ServiceCollectionExtensions.cs @@ -11,24 +11,22 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddShopeeSDK(this IServiceCollection services, IConfigurationSection configurationSection, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton) { - services.AddShopeeSDKCore(serviceLifetime); - - services.Configure(configurationSection); + services.AddShopeeSDK(configurationSection.Bind, serviceLifetime); return services; } - public static IServiceCollection AddShopeeSDK(this IServiceCollection services, Action setupAction, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton) + public static IServiceCollection AddShopeeSDK(this IServiceCollection services, Action configure = null, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton) { - services.AddShopeeSDKCore(serviceLifetime); + var options = new ShopeeSDKOptions(); - services.Configure(setupAction); + if (configure != null) + { + configure.Invoke(options); + } + + services.TryAddSingleton(options); - return services; - } - - internal static IServiceCollection AddShopeeSDKCore(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Singleton) - { services.TryAdd(new ServiceDescriptor(typeof(IShopeeClient), typeof(ShopeeClient), serviceLifetime)); return services; diff --git a/src/JustCSharp.ShopeeSDK/ShopeeClient.cs b/src/JustCSharp.ShopeeSDK/ShopeeClient.cs index 583a04f..a5cb16b 100644 --- a/src/JustCSharp.ShopeeSDK/ShopeeClient.cs +++ b/src/JustCSharp.ShopeeSDK/ShopeeClient.cs @@ -24,11 +24,11 @@ public class ShopeeClient : IShopeeClient, IDisposable protected readonly ILogger _logger; protected readonly ShopeeSDKOptions _shopeeSdkOptions; - public ShopeeClient(IOptions shopeeOptions, ILogger logger) + public ShopeeClient(ShopeeSDKOptions shopeeSdkOptions, ILogger logger) { _httpClient = new RestClient(new RestClientOptions()).UseSystemTextJson(); _logger = logger; - _shopeeSdkOptions = shopeeOptions.Value; + _shopeeSdkOptions = shopeeSdkOptions; } public T Execute(IShopeeRequest request) where T : IShopeeResponse