2020-02-24 16:18:47 +01:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-03-16 14:02:08 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-02-18 08:32:06 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-02-27 11:48:38 +01:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-02-25 08:56:58 +01:00
|
|
|
using Umbraco.Composing;
|
2020-03-16 14:02:08 +01:00
|
|
|
using Umbraco.Configuration;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
using Umbraco.Core.Configuration;
|
2020-03-16 19:00:18 +01:00
|
|
|
using Umbraco.Core.Configuration.HealthChecks;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
using Umbraco.Core.Logging.Serilog;
|
2020-02-18 08:32:06 +01:00
|
|
|
|
|
|
|
|
namespace Umbraco.Web.BackOffice.AspNetCore
|
|
|
|
|
{
|
|
|
|
|
public static class UmbracoBackOfficeServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddUmbracoBackOffice(this IServiceCollection services)
|
|
|
|
|
{
|
2020-03-16 14:02:08 +01:00
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
2020-02-24 16:18:47 +01:00
|
|
|
|
2020-03-16 14:02:08 +01:00
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
var httpContextAccessor = serviceProvider.GetService<IHttpContextAccessor>();
|
|
|
|
|
var webHostEnvironment = serviceProvider.GetService<IWebHostEnvironment>();
|
|
|
|
|
var hostApplicationLifetime = serviceProvider.GetService<IHostApplicationLifetime>();
|
|
|
|
|
var configuration = serviceProvider.GetService<IConfiguration>();
|
|
|
|
|
|
|
|
|
|
var configsFactory = new AspNetCoreConfigsFactory(configuration);
|
|
|
|
|
var configs = configsFactory.Create();
|
|
|
|
|
|
2020-03-16 19:00:18 +01:00
|
|
|
var settings = configs.GetConfig<IHealthChecksSettings>();
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
services.CreateCompositionRoot(
|
|
|
|
|
httpContextAccessor,
|
|
|
|
|
webHostEnvironment,
|
|
|
|
|
hostApplicationLifetime,
|
|
|
|
|
configsFactory);
|
2020-02-24 16:18:47 +01:00
|
|
|
|
2020-02-18 08:32:06 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 08:56:58 +01:00
|
|
|
|
2020-03-16 14:02:08 +01:00
|
|
|
public static IServiceCollection CreateCompositionRoot(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor,
|
|
|
|
|
IWebHostEnvironment webHostEnvironment,
|
|
|
|
|
IHostApplicationLifetime hostApplicationLifetime,
|
|
|
|
|
IConfigsFactory configsFactory)
|
2020-02-24 16:18:47 +01:00
|
|
|
{
|
|
|
|
|
var configFactory = new ConfigsFactory();
|
|
|
|
|
var hostingSettings = configFactory.HostingSettings;
|
2020-03-16 14:02:08 +01:00
|
|
|
var coreDebug = configFactory.CoreDebugSettings;
|
2020-03-13 10:00:03 +01:00
|
|
|
var globalSettings = configFactory.GlobalSettings;
|
2020-02-24 16:18:47 +01:00
|
|
|
|
2020-02-27 11:48:38 +01:00
|
|
|
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment, httpContextAccessor, hostApplicationLifetime);
|
2020-03-13 10:00:03 +01:00
|
|
|
var ioHelper = new IOHelper(hostingEnvironment, globalSettings);
|
2020-02-24 16:18:47 +01:00
|
|
|
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetCoreSessionIdResolver(httpContextAccessor), () => services.BuildServiceProvider().GetService<IRequestCache>(), coreDebug, ioHelper, new AspNetCoreMarchal());
|
2020-03-13 12:45:22 +01:00
|
|
|
var configs = configFactory.Create();
|
2020-03-12 16:56:39 +01:00
|
|
|
|
2020-03-13 10:00:03 +01:00
|
|
|
var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
|
2020-02-24 16:18:47 +01:00
|
|
|
var profiler = new LogProfiler(logger);
|
|
|
|
|
|
2020-02-25 08:56:58 +01:00
|
|
|
Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
return services;
|
2020-02-24 16:18:47 +01:00
|
|
|
}
|
2020-02-18 08:32:06 +01:00
|
|
|
}
|
|
|
|
|
}
|