2020-03-25 20:42:02 +01:00
|
|
|
using System;
|
2020-11-19 20:47:41 +00:00
|
|
|
using System.Collections.Generic;
|
2020-03-25 20:42:02 +01:00
|
|
|
using System.Data.Common;
|
2020-04-27 10:09:10 +02:00
|
|
|
using System.Data.SqlClient;
|
2020-11-20 11:11:52 +00:00
|
|
|
using System.Drawing;
|
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-11-20 11:11:52 +00:00
|
|
|
using Microsoft.Extensions.Hosting;
|
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-03-24 14:48:32 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the Umbraco Back Core requirements
|
|
|
|
|
/// </summary>
|
2020-11-19 20:47:41 +00:00
|
|
|
/// <param name="builder"></param>
|
2020-03-25 18:21:44 +11:00
|
|
|
/// <param name="webHostEnvironment"></param>
|
2020-03-24 14:48:32 +11:00
|
|
|
/// <param name="entryAssembly"></param>
|
2020-11-19 20:47:41 +00:00
|
|
|
/// <param name="appCaches"></param>
|
2020-09-02 18:10:29 +10:00
|
|
|
/// <param name="loggingConfiguration"></param>
|
2020-11-19 20:47:41 +00:00
|
|
|
/// <param name="configuration"></param>
|
2020-09-02 18:10:29 +10:00
|
|
|
/// <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-11-20 11:11:52 +00:00
|
|
|
IConfiguration configuration)
|
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-11-19 20:47:41 +00:00
|
|
|
var syntaxProviders = new List<ISqlSyntaxProvider>();
|
|
|
|
|
var insertProviders = new List<IBulkSqlInsertProvider>();
|
|
|
|
|
var databaseCreators = new List<IEmbeddedDatabaseCreator>();
|
2020-10-14 11:35:38 +02:00
|
|
|
|
2020-08-04 12:54:54 +02:00
|
|
|
// Add supported databases
|
2020-11-19 20:47:41 +00:00
|
|
|
builder.Services.AddUmbracoSqlCeSupport(syntaxProviders, insertProviders, databaseCreators);
|
|
|
|
|
builder.Services.AddUmbracoSqlServerSupport(syntaxProviders, insertProviders, databaseCreators);
|
2020-05-08 17:30:30 +10:00
|
|
|
|
2020-11-19 20:47:41 +00:00
|
|
|
var dbProviderFactoryCreator = new DbProviderFactoryCreator(
|
2020-05-06 20:37:03 +02:00
|
|
|
DbProviderFactories.GetFactory,
|
2020-11-19 20:47:41 +00:00
|
|
|
syntaxProviders,
|
|
|
|
|
insertProviders,
|
|
|
|
|
databaseCreators);
|
2020-09-15 15:14:44 +02:00
|
|
|
|
2020-11-19 20:47:41 +00:00
|
|
|
builder.Services.AddSingleton<IDbProviderFactoryCreator>(dbProviderFactoryCreator);
|
2020-08-21 14:52:47 +01:00
|
|
|
|
2020-11-20 11:11:52 +00:00
|
|
|
builder.Services.AddUnique<IIOHelper, IOHelper>();
|
|
|
|
|
builder.Services.AddLogger(loggingConfiguration, configuration); // TODO: remove this line
|
|
|
|
|
var loggerFactory = builder.BuilderLoggerFactory;
|
|
|
|
|
|
|
|
|
|
var profiler = GetWebProfiler(configuration);
|
|
|
|
|
builder.Services.AddUnique<IProfiler>(profiler);
|
|
|
|
|
|
|
|
|
|
var profilingLogger = new ProfilingLogger(builder.BuilderLoggerFactory.CreateLogger<ProfilingLogger>(), profiler);
|
|
|
|
|
builder.Services.AddUnique<IProfilingLogger>(profilingLogger);
|
|
|
|
|
|
|
|
|
|
var typeFinder = CreateTypeFinder(loggerFactory, webHostEnvironment, entryAssembly, builder.Config);
|
|
|
|
|
builder.Services.AddUnique<ITypeFinder>(typeFinder);
|
2020-02-24 16:18:47 +01:00
|
|
|
|
2020-11-20 11:11:52 +00:00
|
|
|
var typeLoader = CreateTypeLoader(typeFinder, webHostEnvironment, loggerFactory, profilingLogger, appCaches.RuntimeCache, configuration);
|
|
|
|
|
builder.TypeLoader = typeLoader;
|
|
|
|
|
builder.Services.AddUnique<TypeLoader>(typeLoader);
|
2020-10-06 21:23:15 +02:00
|
|
|
|
2020-11-19 20:47:41 +00:00
|
|
|
builder.Services.AddUnique<IBackOfficeInfo, AspNetCoreBackOfficeInfo>();
|
|
|
|
|
|
2020-11-20 11:11:52 +00:00
|
|
|
// 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);
|
2020-03-13 19:10:21 +11:00
|
|
|
|
2020-11-20 11:11:52 +00:00
|
|
|
builder.Services.AddUnique<AppCaches>(appCaches);
|
|
|
|
|
builder.Services.AddUnique<IRequestCache>(appCaches.RequestCache);
|
|
|
|
|
builder.Services.AddUnique<IUmbracoVersion, UmbracoVersion>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IDbProviderFactoryCreator>(dbProviderFactoryCreator);
|
|
|
|
|
builder.Services.AddUnique<IRuntime, CoreRuntime>();
|
|
|
|
|
builder.Services.AddUnique<IRuntimeState, RuntimeState>();
|
|
|
|
|
builder.Services.AddUnique<IHostingEnvironment, AspNetCoreHostingEnvironment>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IMainDomLock>(factory =>
|
|
|
|
|
{
|
|
|
|
|
var globalSettings = factory.GetRequiredService<IOptions<GlobalSettings>>().Value;
|
|
|
|
|
var connectionStrings = factory.GetRequiredService<IOptions<ConnectionStrings>>().Value;
|
|
|
|
|
var hostingEnvironment = factory.GetRequiredService<IHostingEnvironment>();
|
|
|
|
|
|
|
|
|
|
var dbCreator = factory.GetRequiredService<IDbProviderFactoryCreator>()
|
|
|
|
|
; var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
|
|
|
|
|
|
|
|
return globalSettings.MainDomLock.Equals("SqlMainDomLock") || isWindows == false
|
|
|
|
|
? (IMainDomLock)new SqlMainDomLock(builder.BuilderLoggerFactory.CreateLogger<SqlMainDomLock>(), builder.BuilderLoggerFactory, globalSettings, connectionStrings, dbCreator, hostingEnvironment)
|
|
|
|
|
: new MainDomSemaphoreLock(builder.BuilderLoggerFactory.CreateLogger<MainDomSemaphoreLock>(), hostingEnvironment);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IMainDom, MainDom>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IUmbracoBootPermissionChecker>(new AspNetCoreBootPermissionsChecker());
|
2020-03-13 18:44:58 +11:00
|
|
|
|
2020-11-19 16:20:39 +00:00
|
|
|
builder.AddComposers();
|
|
|
|
|
|
2020-11-20 11:11:52 +00:00
|
|
|
var exceptionLogger = builder.BuilderLoggerFactory.CreateLogger<object>();
|
|
|
|
|
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 += ".";
|
|
|
|
|
exceptionLogger.LogError(exception, msg);
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-19 16:20:39 +00:00
|
|
|
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>
|
2020-11-19 20:47:41 +00:00
|
|
|
private static IServiceCollection AddUmbracoSqlCeSupport(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
ICollection<ISqlSyntaxProvider> syntaxProviders,
|
|
|
|
|
ICollection<IBulkSqlInsertProvider> insertProviders,
|
|
|
|
|
ICollection<IEmbeddedDatabaseCreator> databaseCreators)
|
2020-10-30 13:56:13 +01:00
|
|
|
{
|
|
|
|
|
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);
|
2020-11-19 20:47:41 +00:00
|
|
|
|
|
|
|
|
syntaxProviders.Add((ISqlSyntaxProvider)Activator.CreateInstance(sqlCeSyntaxProviderType));
|
|
|
|
|
insertProviders.Add((IBulkSqlInsertProvider)Activator.CreateInstance(sqlCeBulkSqlInsertProviderType));
|
|
|
|
|
databaseCreators.Add((IEmbeddedDatabaseCreator)Activator.CreateInstance(sqlCeEmbeddedDatabaseCreatorType));
|
2020-10-30 13:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
2020-11-19 20:47:41 +00:00
|
|
|
public static IServiceCollection AddUmbracoSqlServerSupport(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
ICollection<ISqlSyntaxProvider> syntaxProviders,
|
|
|
|
|
ICollection<IBulkSqlInsertProvider> insertProviders,
|
|
|
|
|
ICollection<IEmbeddedDatabaseCreator> databaseCreators)
|
2020-10-30 13:56:13 +01:00
|
|
|
{
|
|
|
|
|
DbProviderFactories.RegisterFactory(Core.Constants.DbProviderNames.SqlServer, SqlClientFactory.Instance);
|
|
|
|
|
|
2020-11-19 20:47:41 +00:00
|
|
|
var syntaxProvider = new SqlServerSyntaxProvider();
|
|
|
|
|
var insertProvider = new SqlServerBulkSqlInsertProvider();
|
|
|
|
|
var databaseCreator = new NoopEmbeddedDatabaseCreator();
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<ISqlSyntaxProvider>(syntaxProvider);
|
|
|
|
|
services.AddSingleton<IBulkSqlInsertProvider>(insertProvider);
|
|
|
|
|
services.AddSingleton<IEmbeddedDatabaseCreator>(databaseCreator);
|
|
|
|
|
|
|
|
|
|
syntaxProviders.Add(syntaxProvider);
|
|
|
|
|
insertProviders.Add(insertProvider);
|
|
|
|
|
databaseCreators.Add(databaseCreator);
|
2020-10-30 13:56:13 +01:00
|
|
|
|
|
|
|
|
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-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-11-20 11:11:52 +00:00
|
|
|
private static IProfiler GetWebProfiler(IConfiguration config)
|
2020-03-25 05:39:25 +01:00
|
|
|
{
|
2020-11-20 11:11:52 +00:00
|
|
|
var isDebug = config.GetValue<bool>($"{Constants.Configuration.ConfigHosting}:Debug");
|
2020-03-25 05:39:25 +01:00
|
|
|
// create and start asap to profile boot
|
2020-11-20 11:11:52 +00:00
|
|
|
if (!isDebug)
|
2020-03-25 05:39:25 +01:00
|
|
|
{
|
|
|
|
|
// 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-11-20 11:11:52 +00:00
|
|
|
private static ITypeFinder CreateTypeFinder(ILoggerFactory loggerFactory, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
var profiler = GetWebProfiler(config);
|
|
|
|
|
|
|
|
|
|
var typeFinderSettings = config.GetSection(Core.Constants.Configuration.ConfigTypeFinder).Get<TypeFinderSettings>() ?? new TypeFinderSettings();
|
|
|
|
|
|
|
|
|
|
var runtimeHashPaths = new RuntimeHashPaths().AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin")));
|
|
|
|
|
var runtimeHash = new RuntimeHash(new ProfilingLogger(loggerFactory.CreateLogger("RuntimeHash"), profiler), runtimeHashPaths);
|
|
|
|
|
|
|
|
|
|
return new TypeFinder(
|
|
|
|
|
loggerFactory.CreateLogger<TypeFinder>(),
|
|
|
|
|
new DefaultUmbracoAssemblyProvider(entryAssembly),
|
|
|
|
|
runtimeHash,
|
|
|
|
|
new TypeFinderConfig(Options.Create(typeFinderSettings))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static TypeLoader CreateTypeLoader(
|
|
|
|
|
ITypeFinder typeFinder,
|
|
|
|
|
IWebHostEnvironment webHostEnvironment,
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IProfilingLogger profilingLogger,
|
|
|
|
|
IAppPolicyCache runtimeCache,
|
|
|
|
|
IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
var hostingSettings = configuration.GetSection(Core.Constants.Configuration.ConfigHosting).Get<HostingSettings>() ?? new HostingSettings();
|
|
|
|
|
var hostingEnvironment = new AspNetCoreHostingEnvironmentWithoutOptionsMonitor(hostingSettings, webHostEnvironment);
|
|
|
|
|
|
|
|
|
|
return new TypeLoader(
|
|
|
|
|
typeFinder,
|
|
|
|
|
runtimeCache,
|
|
|
|
|
new DirectoryInfo(hostingEnvironment.LocalTempPath),
|
|
|
|
|
loggerFactory.CreateLogger<TypeLoader>(),
|
|
|
|
|
profilingLogger
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|