aboutsummaryrefslogtreecommitdiffstats
path: root/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs
blob: d9c9769596f6786b0081f19bc57681881896c17d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using IOL.VippsEcommerce.Models;
using Microsoft.Extensions.DependencyInjection;

namespace IOL.VippsEcommerce
{
	public static class ServiceCollectionExtensions
	{
		/// <summary>
		/// Configures and adds the VippsEcommerceService to your DI. 
		/// </summary>
		/// <param name="services">Servicecollection to add VippsEcommerceService to.</param>
		/// <param name="configuration"></param>
		/// <returns></returns>
		public static IServiceCollection AddVippsEcommerceService(
			this IServiceCollection services,
			Action<VippsConfiguration> 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;
		}
	}
}