-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathAprimoComposer.cs
52 lines (42 loc) · 2.14 KB
/
AprimoComposer.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
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http.Headers;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Integrations.DAM.Aprimo.Configuration;
using Umbraco.Cms.Integrations.DAM.Aprimo.Migrations;
using Umbraco.Cms.Integrations.DAM.Aprimo.Services;
namespace Umbraco.Cms.Integrations.DAM.Aprimo
{
public class AprimoComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services
.AddOptions<AprimoSettings>()
.Bind(builder.Config.GetSection(Constants.SettingsPath));
builder.Services
.AddOptions<AprimoOAuthSettings>()
.Bind(builder.Config.GetSection(Constants.OAuthSettingsPath));
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, UmbracoAppStartingHandler>();
builder.Services.AddSingleton<OAuthConfigurationStorage>();
builder.Services.AddSingleton<IAprimoAuthorizationService, AprimoAuthorizationService>();
builder.Services.AddSingleton<IAprimoService, AprimoService>();
builder.Services
.AddHttpClient(Constants.AprimoClient, client =>
{
client.BaseAddress =
new Uri($"https://{builder.Config.GetSection(Constants.SettingsPath)[nameof(AprimoSettings.Tenant)]}.dam.aprimo.com/api/core/");
client.DefaultRequestHeaders.Add("API-VERSION", "1");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Umbraco.Cms.Integrations.DAM.Aprimo", "1.0.0"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
});
builder.Services
.AddHttpClient(Constants.AprimoAuthClient, client =>
{
client.BaseAddress =
new Uri($"https://{builder.Config.GetSection(Constants.SettingsPath)[nameof(AprimoSettings.Tenant)]}.aprimo.com/");
});
}
}
}