From aae8cac8dfd0bf904c6b8761fec1587ef467c30c Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Fri, 2 Apr 2021 19:16:39 +0200 Subject: Make configuration from DI-init optional --- .../ServiceCollectionExtensions.cs | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs') diff --git a/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs b/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs index d9c9769..1637dc9 100644 --- a/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs +++ b/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs @@ -16,13 +16,31 @@ namespace IOL.VippsEcommerce this IServiceCollection services, Action configuration ) { - if (services == null) throw new ArgumentNullException(nameof(services)); - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - + if (services == null) + throw new ArgumentNullException(nameof(services)); + if (configuration == null) + throw new ArgumentNullException(nameof(configuration)); services.Configure(configuration); services.AddHttpClient(); services.AddScoped(); return services; } + + /// + /// Adds the VippsEcommerceService to your DI, and expects configuration values from environment variables. + /// + /// Servicecollection to add VippsEcommerceService to. + /// + public static IServiceCollection AddVippsEcommerceService( + this IServiceCollection services + ) { + if (services == null) + throw new ArgumentNullException(nameof(services)); + services.Configure(new Action(o => o.ConfigurationMode = + VippsConfigurationMode.ONLY_ENVIRONMENT)); + services.AddHttpClient(); + services.AddScoped(); + return services; + } } } \ No newline at end of file -- cgit v1.3