2020-02-25 08:56:58 +01:00
|
|
|
using System.Configuration;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
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-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core;
|
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
using Umbraco.Core.Logging.Serilog;
|
2020-02-25 08:56:58 +01:00
|
|
|
using Umbraco.Core.Runtime;
|
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-02-24 16:18:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
|
|
|
|
|
CreateCompositionRoot(services);
|
|
|
|
|
|
2020-02-18 08:32:06 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 08:56:58 +01:00
|
|
|
|
2020-02-24 16:18:47 +01:00
|
|
|
private static void CreateCompositionRoot(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
var httpContextAccessor = serviceProvider.GetService<IHttpContextAccessor>();
|
|
|
|
|
var webHostEnvironment = serviceProvider.GetService<IWebHostEnvironment>();
|
2020-02-27 11:48:38 +01:00
|
|
|
var hostApplicationLifetime = serviceProvider.GetService<IHostApplicationLifetime>();
|
2020-02-24 16:18:47 +01:00
|
|
|
|
|
|
|
|
var configFactory = new ConfigsFactory();
|
|
|
|
|
|
|
|
|
|
var hostingSettings = configFactory.HostingSettings;
|
|
|
|
|
var coreDebug = configFactory.CoreDebug;
|
|
|
|
|
|
2020-02-27 11:48:38 +01:00
|
|
|
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment, httpContextAccessor, hostApplicationLifetime);
|
2020-02-24 16:18:47 +01:00
|
|
|
var ioHelper = new IOHelper(hostingEnvironment);
|
|
|
|
|
var configs = configFactory.Create(ioHelper);
|
|
|
|
|
|
|
|
|
|
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetCoreSessionIdResolver(httpContextAccessor), () => services.BuildServiceProvider().GetService<IRequestCache>(), coreDebug, ioHelper, new AspNetCoreMarchal());
|
|
|
|
|
var backOfficeInfo = new AspNetCoreBackOfficeInfo(configs.Global());
|
|
|
|
|
var profiler = new LogProfiler(logger);
|
|
|
|
|
|
2020-02-25 08:56:58 +01:00
|
|
|
Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler);
|
2020-02-24 16:18:47 +01:00
|
|
|
}
|
2020-02-18 08:32:06 +01:00
|
|
|
}
|
|
|
|
|
}
|