-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOntraportApiServiceCollectionExtensions.cs
81 lines (71 loc) · 4.16 KB
/
OntraportApiServiceCollectionExtensions.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using Microsoft.Extensions.DependencyInjection.Extensions;
using HanumanInstitute.OntraportApi;
using HanumanInstitute.OntraportApi.Models;
// ReSharper disable once CheckNamespace - MS guidelines say put DI registration in this NS
namespace Microsoft.Extensions.DependencyInjection;
public static class OntraportApiServiceCollectionExtensions
{
/// <summary>
/// Registers OntraportApi classes into the IoC container.
/// </summary>
/// <param name="services">The IoC services container.</param>
public static IServiceCollection AddOntraportApi(this IServiceCollection services) =>
AddOntraportApi(services, null);
/// <summary>
/// Registers OntraportApi classes into the IoC container.
/// </summary>
/// <param name="services">The IoC services container.</param>
/// <param name="additionalHttpConfig">Additional configuration to be applied to HttpClient connections.</param>
public static IServiceCollection AddOntraportApi(this IServiceCollection services, Action<IHttpClientBuilder>? additionalHttpConfig)
{
if (services == null) throw new ArgumentNullException(nameof(services));
var ontraClient = services.AddHttpClient<OntraportHttpClient>();
var formsClient = services.AddHttpClient<IOntraportPostForms, OntraportPostForms>();
if (additionalHttpConfig != null)
{
additionalHttpConfig(ontraClient);
additionalHttpConfig(formsClient);
}
services.TryAddTransient<IOntraportCampaignBuilderItems, OntraportCampaignBuilderItems>();
services.TryAddTransient<IOntraportCompanies<ApiCompany>, OntraportCompanies<ApiCompany>>();
services.TryAddTransient<IOntraportContacts<ApiContact>, OntraportContacts<ApiContact>>();
services.TryAddTransient<IOntraportCoupons, OntraportCoupons>();
services.TryAddTransient<IOntraportCouponCodes, OntraportCouponCodes>();
services.TryAddTransient<IOntraportCouponProducts, OntraportCouponProducts>();
services.TryAddTransient<IOntraportCreditCards, OntraportCreditCards>();
services.TryAddTransient<IOntraportCustomObjects, OntraportCustomObjects>();
services.TryAddTransient<IOntraportDeals<ApiDeal>, OntraportDeals<ApiDeal>>();
services.TryAddTransient<IOntraportForms, OntraportForms>();
services.TryAddTransient<IOntraportLandingPages, OntraportLandingPages>();
services.TryAddTransient<IOntraportMessages, OntraportMessages>();
services.TryAddTransient<IOntraportObjects, OntraportObjects>();
services.TryAddTransient<IOntraportOffers, OntraportOffers>();
services.TryAddTransient<IOntraportProducts, OntraportProducts>();
services.TryAddTransient<IOntraportPurchases, OntraportPurchases>();
services.TryAddTransient<IOntraportRules, OntraportRules>();
services.TryAddTransient<IOntraportTasks, OntraportTasks>();
services.TryAddTransient<IOntraportTransactions, OntraportTransactions>();
services.TryAddTransient<IOntraportWebhooks, OntraportWebhooks>();
return services;
}
/// <summary>
/// Registers only OntraportApi classes to post forms, without adding the API.
/// </summary>
/// <param name="services">The IoC services container.</param>
public static IServiceCollection AddOntraportPostForms(this IServiceCollection services) =>
AddOntraportPostForms(services, null);
/// <summary>
/// Registers only OntraportApi classes to post forms, without adding the API.
/// </summary>
/// <param name="services">The IoC services container.</param>
/// <param name="additionalHttpConfig">Additional configuration to be applied to HttpClient connections.</param>
public static IServiceCollection AddOntraportPostForms(this IServiceCollection services, Action<IHttpClientBuilder>? additionalHttpConfig)
{
if (services == null) throw new ArgumentNullException(nameof(services));
var ontraClient = services.AddHttpClient<OntraportHttpClient>();
var formsClient = services.AddHttpClient<IOntraportPostForms, OntraportPostForms>();
additionalHttpConfig?.Invoke(formsClient);
return services;
}
}