diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-04-02 19:16:39 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-04-02 22:35:57 +0200 |
| commit | aae8cac8dfd0bf904c6b8761fec1587ef467c30c (patch) | |
| tree | 531011c5593f7b5884473ced2d6d5b2d5fc641e4 /src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs | |
| parent | 78f6e40f0df706a18fa3489e8cce9c36de55859f (diff) | |
| download | dotnet-vipps-ecommerce-aae8cac8dfd0bf904c6b8761fec1587ef467c30c.tar.xz dotnet-vipps-ecommerce-aae8cac8dfd0bf904c6b8761fec1587ef467c30c.zip | |
Make configuration from DI-init optional
Diffstat (limited to 'src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs')
| -rw-r--r-- | src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs | 24 |
1 files changed, 21 insertions, 3 deletions
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<VippsConfiguration> 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<IVippsEcommerceService, VippsEcommerceService>(); services.AddScoped<IVippsEcommerceService, VippsEcommerceService>(); return services; } + + /// <summary> + /// Adds the VippsEcommerceService to your DI, and expects configuration values from environment variables. + /// </summary> + /// <param name="services">Servicecollection to add VippsEcommerceService to.</param> + /// <returns></returns> + public static IServiceCollection AddVippsEcommerceService( + this IServiceCollection services + ) { + if (services == null) + throw new ArgumentNullException(nameof(services)); + services.Configure(new Action<VippsConfiguration>(o => o.ConfigurationMode = + VippsConfigurationMode.ONLY_ENVIRONMENT)); + services.AddHttpClient<IVippsEcommerceService, VippsEcommerceService>(); + services.AddScoped<IVippsEcommerceService, VippsEcommerceService>(); + return services; + } } }
\ No newline at end of file |
