2020-03-25 20:42:02 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Data.Common;
|
2020-04-27 10:09:10 +02:00
|
|
|
using System.Data.SqlClient;
|
2020-04-03 01:08:52 +11:00
|
|
|
using System.IO;
|
2020-03-25 20:42:02 +01:00
|
|
|
using System.Reflection;
|
2020-05-19 09:45:31 +02:00
|
|
|
using System.Runtime.InteropServices;
|
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-04-22 14:23:56 +10:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-08-21 14:52:47 +01:00
|
|
|
using Microsoft.Extensions.Options;
|
2020-04-22 14:23:56 +10:00
|
|
|
using Serilog;
|
|
|
|
|
using Serilog.Extensions.Hosting;
|
2020-03-16 19:14:04 +01:00
|
|
|
using Umbraco.Core;
|
2020-11-18 17:40:23 +00:00
|
|
|
using Umbraco.Core.Builder;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core.Cache;
|
2020-03-13 18:44:58 +11:00
|
|
|
using Umbraco.Core.Composing;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core.Configuration;
|
2020-08-21 14:52:47 +01:00
|
|
|
using Umbraco.Core.Configuration.Models;
|
2020-09-18 11:30:26 +02:00
|
|
|
using Umbraco.Core.Configuration.Models.Validation;
|
2020-02-24 16:18:47 +01:00
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
using Umbraco.Core.Logging.Serilog;
|
2020-03-13 18:44:58 +11:00
|
|
|
using Umbraco.Core.Persistence;
|
2020-05-06 20:37:03 +02:00
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
2020-02-25 08:56:58 +01:00
|
|
|
using Umbraco.Core.Runtime;
|
2020-10-30 13:56:13 +01:00
|
|
|
using Umbraco.Infrastructure.HostedServices;
|
2020-11-10 20:02:09 +01:00
|
|
|
using Umbraco.Infrastructure.HostedServices.ServerRegistration;
|
2020-03-31 12:22:11 +02:00
|
|
|
using Umbraco.Web.Common.AspNetCore;
|
2020-05-12 10:21:40 +10:00
|
|
|
using Umbraco.Web.Common.Profiler;
|
2020-08-23 15:58:37 +02:00
|
|
|
using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings;
|
2020-09-07 15:28:58 +02:00
|
|
|
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
|
2020-02-18 08:32:06 +01:00
|
|
|
|
2020-05-07 10:08:23 +02:00
|
|
|
namespace Umbraco.Extensions
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
2020-03-24 14:48:32 +11:00
|
|
|
public static class UmbracoCoreServiceCollectionExtensions
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
2020-11-19 20:05:28 +00:00
|
|
|
|
2020-03-13 19:10:21 +11:00
|
|
|
|
2020-03-24 14:48:32 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the Umbraco Back Core requirements
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
2020-03-25 18:21:44 +11:00
|
|
|
/// <param name="webHostEnvironment"></param>
|
2020-03-24 14:48:32 +11:00
|
|
|
/// <param name="umbContainer"></param>
|
|
|
|
|
/// <param name="entryAssembly"></param>
|
2020-09-07 15:28:58 +02:00
|
|
|
/// <param name="requestCache"></param>
|
2020-09-02 18:10:29 +10:00
|
|
|
/// <param name="httpContextAccessor"></param>
|
|
|
|
|
/// <param name="loggingConfiguration"></param>
|
2020-11-19 20:05:28 +00:00
|
|
|
/// <param name="configureSomeMoreBits">Delegate to create an <see cref="CoreRuntimeBootstrapper"/></param>
|
2020-09-02 18:10:29 +10:00
|
|
|
/// <param name="factory"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-11-18 17:40:23 +00:00
|
|
|
public static IUmbracoBuilder AddUmbracoCore(
|
|
|
|
|
this IUmbracoBuilder builder,
|
2020-09-02 18:10:29 +10:00
|
|
|
IWebHostEnvironment webHostEnvironment,
|
|
|
|
|
Assembly entryAssembly,
|
2020-11-19 20:05:28 +00:00
|
|
|
AppCaches appCaches,
|
2020-09-02 18:10:29 +10:00
|
|
|
ILoggingConfiguration loggingConfiguration,
|
2020-09-17 09:01:10 +02:00
|
|
|
IConfiguration configuration,
|
2020-09-07 15:28:58 +02:00
|
|
|
//TODO: Yep that's extremely ugly
|
2020-11-19 20:05:28 +00:00
|
|
|
Action<IUmbracoBuilder, GlobalSettings, ConnectionStrings, IUmbracoVersion, IIOHelper, ILoggerFactory, IProfiler, IHostingEnvironment, IBackOfficeInfo, ITypeFinder, AppCaches, IDbProviderFactoryCreator> configureSomeMoreBits)
|
2020-02-18 08:32:06 +01:00
|
|
|
{
|
2020-11-18 17:40:23 +00:00
|
|
|
if (builder is null) throw new ArgumentNullException(nameof(builder));
|
2020-03-24 11:53:56 +11:00
|
|
|
if (entryAssembly is null) throw new ArgumentNullException(nameof(entryAssembly));
|
|
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddLazySupport();
|
2020-10-30 11:16:17 +00:00
|
|
|
|
2020-10-14 11:35:38 +02:00
|
|
|
// Add service session
|
|
|
|
|
// This can be overwritten by the user by adding their own call to AddSession
|
|
|
|
|
// since the last call of AddSession take precedence
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddSession(options =>
|
2020-10-14 11:35:38 +02:00
|
|
|
{
|
|
|
|
|
options.Cookie.Name = "UMB_SESSION";
|
|
|
|
|
options.Cookie.HttpOnly = true;
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-04 12:54:54 +02:00
|
|
|
// Add supported databases
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUmbracoSqlCeSupport();
|
|
|
|
|
builder.Services.AddUmbracoSqlServerSupport();
|
2020-05-08 17:30:30 +10:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddSingleton<IDbProviderFactoryCreator>(x => new DbProviderFactoryCreator(
|
2020-05-06 20:37:03 +02:00
|
|
|
DbProviderFactories.GetFactory,
|
|
|
|
|
x.GetServices<ISqlSyntaxProvider>(),
|
|
|
|
|
x.GetServices<IBulkSqlInsertProvider>(),
|
|
|
|
|
x.GetServices<IEmbeddedDatabaseCreator>()
|
|
|
|
|
));
|
|
|
|
|
|
2020-05-08 17:47:21 +10:00
|
|
|
// TODO: We want to avoid pre-resolving a container as much as possible we should not
|
|
|
|
|
// be doing this any more than we are now. The ugly part about this is that the service
|
|
|
|
|
// instances resolved here won't be the same instances resolved from the container
|
|
|
|
|
// later once the true container is built. However! ... in the case of IDbProviderFactoryCreator
|
|
|
|
|
// it will be the same instance resolved later because we are re-registering this instance back
|
|
|
|
|
// into the container. This is not true for `Configs` but we should do that too, see comments in
|
|
|
|
|
// `RegisterEssentials`.
|
2020-11-18 17:40:23 +00:00
|
|
|
var serviceProvider = builder.Services.BuildServiceProvider();
|
2020-09-15 15:14:44 +02:00
|
|
|
|
2020-09-03 12:29:23 +02:00
|
|
|
var globalSettings = serviceProvider.GetService<IOptionsMonitor<GlobalSettings>>();
|
2020-09-03 11:36:57 +02:00
|
|
|
var connectionStrings = serviceProvider.GetService<IOptions<ConnectionStrings>>();
|
2020-09-03 12:29:23 +02:00
|
|
|
var hostingSettings = serviceProvider.GetService<IOptionsMonitor<HostingSettings>>();
|
|
|
|
|
var typeFinderSettings = serviceProvider.GetService<IOptionsMonitor<TypeFinderSettings>>();
|
2020-08-21 14:52:47 +01:00
|
|
|
|
2020-04-29 08:56:42 +02:00
|
|
|
var dbProviderFactoryCreator = serviceProvider.GetRequiredService<IDbProviderFactoryCreator>();
|
2020-02-24 16:18:47 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment);
|
|
|
|
|
var ioHelper = new IOHelper(hostingEnvironment);
|
|
|
|
|
var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
|
|
|
|
|
var profiler = GetWebProfiler(hostingEnvironment);
|
2020-10-06 21:23:15 +02:00
|
|
|
|
2020-11-19 16:20:39 +00:00
|
|
|
builder.Services.AddLogger(loggingConfiguration, configuration);
|
2020-11-19 20:05:28 +00:00
|
|
|
var loggerFactory = builder.BuilderLoggerFactory;
|
2020-03-13 19:10:21 +11:00
|
|
|
|
2020-09-03 11:36:57 +02:00
|
|
|
var umbracoVersion = new UmbracoVersion();
|
2020-09-24 09:39:48 +02:00
|
|
|
var typeFinder = CreateTypeFinder(loggerFactory, profiler, webHostEnvironment, entryAssembly, typeFinderSettings);
|
2020-03-13 18:44:58 +11:00
|
|
|
|
2020-11-19 20:05:28 +00:00
|
|
|
configureSomeMoreBits(
|
|
|
|
|
builder,
|
2020-09-03 12:29:23 +02:00
|
|
|
globalSettings.CurrentValue,
|
2020-09-03 11:36:57 +02:00
|
|
|
connectionStrings.Value,
|
2020-03-13 18:44:58 +11:00
|
|
|
umbracoVersion,
|
2020-03-24 11:53:56 +11:00
|
|
|
ioHelper,
|
2020-09-15 15:14:44 +02:00
|
|
|
loggerFactory,
|
2020-03-24 11:53:56 +11:00
|
|
|
profiler,
|
|
|
|
|
hostingEnvironment,
|
|
|
|
|
backOfficeInfo,
|
2020-04-27 10:09:10 +02:00
|
|
|
typeFinder,
|
2020-09-04 00:27:43 +10:00
|
|
|
appCaches,
|
2020-04-28 07:01:30 +02:00
|
|
|
dbProviderFactoryCreator);
|
2020-03-13 18:44:58 +11:00
|
|
|
|
2020-11-19 16:20:39 +00:00
|
|
|
builder.AddComposers();
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IUmbracoBuilder AddComposers(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
var composerTypes = builder.TypeLoader.GetTypes<IComposer>();
|
|
|
|
|
var enableDisable = builder.TypeLoader.GetAssemblyAttributes(typeof(EnableComposerAttribute), typeof(DisableComposerAttribute));
|
|
|
|
|
new Composers(builder, composerTypes, enableDisable, builder.BuilderLoggerFactory.CreateLogger<Composers>()).Compose();
|
|
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
return builder;
|
2020-06-30 20:11:39 +02:00
|
|
|
}
|
2020-05-06 20:37:03 +02:00
|
|
|
|
2020-10-30 13:56:13 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds SqlCe support for Umbraco
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static IServiceCollection AddUmbracoSqlCeSupport(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var binFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
if (binFolder != null)
|
|
|
|
|
{
|
|
|
|
|
var dllPath = Path.Combine(binFolder, "Umbraco.Persistance.SqlCe.dll");
|
|
|
|
|
var umbSqlCeAssembly = Assembly.LoadFrom(dllPath);
|
|
|
|
|
|
|
|
|
|
var sqlCeSyntaxProviderType = umbSqlCeAssembly.GetType("Umbraco.Persistance.SqlCe.SqlCeSyntaxProvider");
|
|
|
|
|
var sqlCeBulkSqlInsertProviderType = umbSqlCeAssembly.GetType("Umbraco.Persistance.SqlCe.SqlCeBulkSqlInsertProvider");
|
|
|
|
|
var sqlCeEmbeddedDatabaseCreatorType = umbSqlCeAssembly.GetType("Umbraco.Persistance.SqlCe.SqlCeEmbeddedDatabaseCreator");
|
|
|
|
|
|
|
|
|
|
if (!(sqlCeSyntaxProviderType is null || sqlCeBulkSqlInsertProviderType is null || sqlCeEmbeddedDatabaseCreatorType is null))
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton(typeof(ISqlSyntaxProvider), sqlCeSyntaxProviderType);
|
|
|
|
|
services.AddSingleton(typeof(IBulkSqlInsertProvider), sqlCeBulkSqlInsertProviderType);
|
|
|
|
|
services.AddSingleton(typeof(IEmbeddedDatabaseCreator), sqlCeEmbeddedDatabaseCreatorType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sqlCeAssembly = Assembly.LoadFrom(Path.Combine(binFolder, "System.Data.SqlServerCe.dll"));
|
|
|
|
|
|
|
|
|
|
var sqlCe = sqlCeAssembly.GetType("System.Data.SqlServerCe.SqlCeProviderFactory");
|
|
|
|
|
if (!(sqlCe is null))
|
|
|
|
|
{
|
|
|
|
|
DbProviderFactories.RegisterFactory(Core.Constants.DbProviderNames.SqlCe, sqlCe);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore if SqlCE is not available
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds Sql Server support for Umbraco
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IServiceCollection AddUmbracoSqlServerSupport(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
DbProviderFactories.RegisterFactory(Core.Constants.DbProviderNames.SqlServer, SqlClientFactory.Instance);
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<ISqlSyntaxProvider, SqlServerSyntaxProvider>();
|
|
|
|
|
services.AddSingleton<IBulkSqlInsertProvider, SqlServerBulkSqlInsertProvider>();
|
|
|
|
|
services.AddSingleton<IEmbeddedDatabaseCreator, NoopEmbeddedDatabaseCreator>();
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds hosted services for Umbraco.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IServiceCollection AddUmbracoHostedServices(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddHostedService<HealthCheckNotifier>();
|
2020-10-30 17:19:01 +01:00
|
|
|
services.AddHostedService<KeepAlive>();
|
2020-10-31 14:13:24 +01:00
|
|
|
services.AddHostedService<LogScrubber>();
|
2020-11-02 18:08:25 +01:00
|
|
|
services.AddHostedService<ScheduledPublishing>();
|
2020-10-31 08:58:47 +01:00
|
|
|
services.AddHostedService<TempFileCleanup>();
|
2020-10-31 14:13:24 +01:00
|
|
|
|
2020-11-10 20:02:09 +01:00
|
|
|
services.AddHostedService<InstructionProcessTask>();
|
|
|
|
|
services.AddHostedService<TouchServerTask>();
|
|
|
|
|
|
2020-10-30 17:19:01 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
2020-10-30 13:56:13 +01:00
|
|
|
|
2020-10-30 17:19:01 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds HTTP clients for Umbraco.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IServiceCollection AddUmbracoHttpClients(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddHttpClient();
|
2020-10-30 13:56:13 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 12:53:06 +02:00
|
|
|
private static ITypeFinder CreateTypeFinder(ILoggerFactory loggerFactory, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IOptionsMonitor<TypeFinderSettings> typeFinderSettings)
|
2020-04-03 01:08:52 +11:00
|
|
|
{
|
|
|
|
|
var runtimeHashPaths = new RuntimeHashPaths();
|
|
|
|
|
runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin")));
|
2020-09-16 14:29:33 +02:00
|
|
|
var runtimeHash = new RuntimeHash(new ProfilingLogger(loggerFactory.CreateLogger("RuntimeHash"), profiler), runtimeHashPaths);
|
2020-09-16 13:08:27 +02:00
|
|
|
return new TypeFinder(loggerFactory.CreateLogger<TypeFinder>(), new DefaultUmbracoAssemblyProvider(entryAssembly), runtimeHash, new TypeFinderConfig(typeFinderSettings));
|
2020-04-03 01:08:52 +11:00
|
|
|
}
|
|
|
|
|
|
2020-11-19 20:05:28 +00:00
|
|
|
internal static void ConfigureSomeMorebits(
|
|
|
|
|
IUmbracoBuilder builder,
|
|
|
|
|
GlobalSettings globalSettings,
|
|
|
|
|
ConnectionStrings connectionStrings,
|
|
|
|
|
IUmbracoVersion umbracoVersion,
|
|
|
|
|
IIOHelper ioHelper,
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IProfiler profiler,
|
|
|
|
|
IHostingEnvironment hostingEnvironment,
|
|
|
|
|
IBackOfficeInfo backOfficeInfo,
|
|
|
|
|
ITypeFinder typeFinder,
|
|
|
|
|
AppCaches appCaches,
|
|
|
|
|
IDbProviderFactoryCreator dbProviderFactoryCreator)
|
2020-03-13 18:44:58 +11:00
|
|
|
{
|
|
|
|
|
// Determine if we should use the sql main dom or the default
|
2020-03-23 15:50:01 +11:00
|
|
|
var appSettingMainDomLock = globalSettings.MainDomLock;
|
2020-06-25 11:39:11 +02:00
|
|
|
|
2020-08-19 09:39:11 +02:00
|
|
|
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
|
|
|
var mainDomLock = appSettingMainDomLock == "SqlMainDomLock" || isWindows == false
|
2020-09-18 12:53:06 +02:00
|
|
|
? (IMainDomLock)new SqlMainDomLock(loggerFactory.CreateLogger<SqlMainDomLock>(), loggerFactory, globalSettings, connectionStrings, dbProviderFactoryCreator, hostingEnvironment)
|
2020-09-16 14:29:33 +02:00
|
|
|
: new MainDomSemaphoreLock(loggerFactory.CreateLogger<MainDomSemaphoreLock>(), hostingEnvironment);
|
2020-03-13 18:44:58 +11:00
|
|
|
|
2020-09-16 14:29:33 +02:00
|
|
|
var mainDom = new MainDom(loggerFactory.CreateLogger<MainDom>(), mainDomLock);
|
2020-03-13 18:44:58 +11:00
|
|
|
|
|
|
|
|
|
2020-11-19 20:05:28 +00:00
|
|
|
var logger = builder.BuilderLoggerFactory.CreateLogger<object>();
|
|
|
|
|
var profilingLogger = new ProfilingLogger(logger, profiler);
|
|
|
|
|
|
|
|
|
|
AppDomain.CurrentDomain.SetData("DataDirectory", hostingEnvironment?.MapPathContentRoot(Constants.SystemDirectories.Data));
|
|
|
|
|
|
|
|
|
|
// application environment
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
|
|
|
|
|
{
|
|
|
|
|
var exception = (Exception)args.ExceptionObject;
|
|
|
|
|
var isTerminating = args.IsTerminating; // always true?
|
|
|
|
|
|
|
|
|
|
var msg = "Unhandled exception in AppDomain";
|
|
|
|
|
if (isTerminating) msg += " (terminating)";
|
|
|
|
|
msg += ".";
|
|
|
|
|
logger.LogError(exception, msg);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: Don't do this, UmbracoBuilder ctor should handle it...
|
|
|
|
|
builder.TypeLoader = new TypeLoader(typeFinder, appCaches.RuntimeCache,
|
|
|
|
|
new DirectoryInfo(hostingEnvironment.LocalTempPath),
|
|
|
|
|
builder.BuilderLoggerFactory.CreateLogger<TypeLoader>(), profilingLogger);
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IUmbracoBootPermissionChecker>(new AspNetCoreBootPermissionsChecker());
|
|
|
|
|
builder.Services.AddUnique<IProfiler>(profiler);
|
|
|
|
|
builder.Services.AddUnique<IProfilingLogger>(profilingLogger);
|
|
|
|
|
builder.Services.AddUnique<IMainDom>(mainDom);
|
|
|
|
|
builder.Services.AddUnique<AppCaches>(appCaches);
|
|
|
|
|
builder.Services.AddUnique<IRequestCache>(appCaches.RequestCache);
|
|
|
|
|
builder.Services.AddUnique<TypeLoader>(builder.TypeLoader);
|
|
|
|
|
builder.Services.AddUnique<ITypeFinder>(typeFinder);
|
|
|
|
|
builder.Services.AddUnique<IIOHelper>(ioHelper);
|
|
|
|
|
builder.Services.AddUnique<IUmbracoVersion>(umbracoVersion);
|
|
|
|
|
builder.Services.AddUnique<IDbProviderFactoryCreator>(dbProviderFactoryCreator);
|
|
|
|
|
builder.Services.AddUnique<IHostingEnvironment>(hostingEnvironment);
|
|
|
|
|
builder.Services.AddUnique<IBackOfficeInfo>(backOfficeInfo);
|
|
|
|
|
builder.Services.AddUnique<IRuntime, CoreRuntime>();
|
|
|
|
|
|
|
|
|
|
// after bootstrapping we let the container wire up for us.
|
|
|
|
|
builder.Services.AddUnique<IUmbracoDatabaseFactory, UmbracoDatabaseFactory>();
|
|
|
|
|
builder.Services.AddUnique<ISqlContext>(factory => factory.GetRequiredService<IUmbracoDatabaseFactory>().SqlContext);
|
|
|
|
|
builder.Services.AddUnique<IBulkSqlInsertProvider>(factory => factory.GetRequiredService<IUmbracoDatabaseFactory>().BulkSqlInsertProvider);
|
|
|
|
|
|
|
|
|
|
// re-create the state object with the essential services
|
|
|
|
|
builder.Services.AddUnique<IRuntimeState, RuntimeState>();
|
2020-03-13 18:44:58 +11:00
|
|
|
}
|
2020-02-25 08:56:58 +01:00
|
|
|
|
2020-03-24 10:51:53 +01:00
|
|
|
|
2020-04-22 14:23:56 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create and configure the logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="hostingEnvironment"></param>
|
2020-11-18 17:40:23 +00:00
|
|
|
public static IServiceCollection AddLogger(
|
|
|
|
|
this IServiceCollection services,
|
2020-09-24 09:39:48 +02:00
|
|
|
ILoggingConfiguration loggingConfiguration,
|
2020-10-06 21:23:15 +02:00
|
|
|
IConfiguration configuration)
|
2020-04-22 14:23:56 +10:00
|
|
|
{
|
|
|
|
|
// Create a serilog logger
|
2020-11-19 16:20:39 +00:00
|
|
|
var logger = SerilogLogger.CreateWithDefaultConfiguration(loggingConfiguration, configuration);
|
2020-09-17 09:01:10 +02:00
|
|
|
|
|
|
|
|
// This is nessasary to pick up all the loggins to MS ILogger.
|
|
|
|
|
Log.Logger = logger.SerilogLog;
|
|
|
|
|
|
2020-09-16 14:29:33 +02:00
|
|
|
|
2020-04-22 14:23:56 +10:00
|
|
|
// Wire up all the bits that serilog needs. We need to use our own code since the Serilog ext methods don't cater to our needs since
|
|
|
|
|
// we don't want to use the global serilog `Log` object and we don't have our own ILogger implementation before the HostBuilder runs which
|
2020-04-22 10:29:21 +02:00
|
|
|
// is the only other option that these ext methods allow.
|
2020-04-22 14:23:56 +10:00
|
|
|
// I have created a PR to make this nicer https://github.com/serilog/serilog-extensions-hosting/pull/19 but we'll need to wait for that.
|
|
|
|
|
// Also see : https://github.com/serilog/serilog-extensions-hosting/blob/dev/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs
|
|
|
|
|
|
2020-09-17 09:59:13 +02:00
|
|
|
services.AddLogging(configure =>
|
2020-09-16 14:29:33 +02:00
|
|
|
{
|
2020-09-17 09:59:13 +02:00
|
|
|
configure.AddSerilog(logger.SerilogLog, false);
|
2020-09-16 14:29:33 +02:00
|
|
|
});
|
|
|
|
|
|
2020-10-06 21:23:15 +02:00
|
|
|
// This won't (and shouldn't) take ownership of the logger.
|
|
|
|
|
services.AddSingleton(logger.SerilogLog);
|
2020-09-17 09:01:10 +02:00
|
|
|
|
2020-10-06 21:23:15 +02:00
|
|
|
// Registered to provide two services...
|
|
|
|
|
var diagnosticContext = new DiagnosticContext(logger.SerilogLog);
|
2020-04-22 14:23:56 +10:00
|
|
|
|
2020-10-06 21:23:15 +02:00
|
|
|
// Consumed by e.g. middleware
|
|
|
|
|
services.AddSingleton(diagnosticContext);
|
|
|
|
|
|
|
|
|
|
// Consumed by user code
|
|
|
|
|
services.AddSingleton<IDiagnosticContext>(diagnosticContext);
|
2020-11-18 17:40:23 +00:00
|
|
|
|
|
|
|
|
return services;
|
2020-04-22 14:23:56 +10:00
|
|
|
}
|
|
|
|
|
|
2020-04-22 15:23:51 +10:00
|
|
|
private static IProfiler GetWebProfiler(Umbraco.Core.Hosting.IHostingEnvironment hostingEnvironment)
|
2020-03-25 05:39:25 +01:00
|
|
|
{
|
|
|
|
|
// create and start asap to profile boot
|
|
|
|
|
if (!hostingEnvironment.IsDebugMode)
|
|
|
|
|
{
|
|
|
|
|
// should let it be null, that's how MiniProfiler is meant to work,
|
|
|
|
|
// but our own IProfiler expects an instance so let's get one
|
|
|
|
|
return new VoidProfiler();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 15:23:51 +10:00
|
|
|
var webProfiler = new WebProfiler();
|
2020-03-29 22:35:52 +02:00
|
|
|
webProfiler.StartBoot();
|
2020-03-25 05:39:25 +01:00
|
|
|
|
|
|
|
|
return webProfiler;
|
|
|
|
|
}
|
2020-05-12 10:21:40 +10:00
|
|
|
|
2020-03-13 18:44:58 +11:00
|
|
|
private class AspNetCoreBootPermissionsChecker : IUmbracoBootPermissionChecker
|
|
|
|
|
{
|
|
|
|
|
public void ThrowIfNotPermissions()
|
|
|
|
|
{
|
|
|
|
|
// nothing to check
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-24 14:48:32 +11:00
|
|
|
|
2020-02-18 08:32:06 +01:00
|
|
|
}
|
2020-04-20 06:19:59 +02:00
|
|
|
|
2020-02-18 08:32:06 +01:00
|
|
|
}
|