2020-09-02 18:10:29 +10:00
|
|
|
using System;
|
2020-11-20 12:24:16 +00:00
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Data.SqlClient;
|
2020-11-19 09:06:04 +00:00
|
|
|
using System.IO;
|
2020-12-24 14:29:26 +11:00
|
|
|
using System.Linq;
|
2020-11-19 09:06:04 +00:00
|
|
|
using System.Reflection;
|
2021-03-16 19:19:03 +11:00
|
|
|
using Dazinator.Extensions.FileProviders.GlobPatternFilter;
|
2020-12-03 13:32:04 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-11-19 09:06:04 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
2020-12-03 13:32:04 +00:00
|
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-19 09:06:04 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-11-18 17:40:23 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-11-19 16:20:39 +00:00
|
|
|
using Serilog;
|
2020-11-19 09:06:04 +00:00
|
|
|
using Smidge;
|
2021-03-17 17:44:52 +11:00
|
|
|
using Smidge.FileProcessors;
|
|
|
|
|
using Smidge.InMemory;
|
2020-11-19 09:06:04 +00:00
|
|
|
using Smidge.Nuglify;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Composing;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
|
|
|
|
using Umbraco.Cms.Core.Diagnostics;
|
|
|
|
|
using Umbraco.Cms.Core.Events;
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
using Umbraco.Cms.Core.Logging;
|
|
|
|
|
using Umbraco.Cms.Core.Macros;
|
|
|
|
|
using Umbraco.Cms.Core.Net;
|
2021-05-11 14:33:49 +02:00
|
|
|
using Umbraco.Cms.Core.Notifications;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Templates;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
2021-03-17 17:44:52 +11:00
|
|
|
using Umbraco.Cms.Core.WebAssets;
|
2021-02-12 10:41:07 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.DependencyInjection;
|
2021-02-12 11:03:28 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.HostedServices;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration;
|
2021-02-12 12:40:08 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax;
|
2021-02-10 11:42:04 +01:00
|
|
|
using Umbraco.Cms.Web.Common;
|
|
|
|
|
using Umbraco.Cms.Web.Common.ApplicationModels;
|
|
|
|
|
using Umbraco.Cms.Web.Common.AspNetCore;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Controllers;
|
2021-02-17 15:41:54 +01:00
|
|
|
using Umbraco.Cms.Web.Common.DependencyInjection;
|
2021-02-10 11:42:04 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Localization;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Macros;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Middleware;
|
|
|
|
|
using Umbraco.Cms.Web.Common.ModelBinders;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Mvc;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Profiler;
|
2021-03-17 17:44:52 +11:00
|
|
|
using Umbraco.Cms.Web.Common.RuntimeMinification;
|
2021-02-10 11:42:04 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Security;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Templates;
|
|
|
|
|
using Umbraco.Cms.Web.Common.UmbracoContext;
|
2021-02-09 10:22:42 +01:00
|
|
|
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2021-02-10 11:42:04 +01:00
|
|
|
namespace Umbraco.Extensions
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
|
|
|
|
// TODO: We could add parameters to configure each of these for flexibility
|
2020-12-22 12:16:37 +11:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extension methods for <see cref="IUmbracoBuilder"/> for the common Umbraco functionality
|
|
|
|
|
/// </summary>
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
public static partial class UmbracoBuilderExtensions
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an <see cref="IUmbracoBuilder"/> and registers basic Umbraco services
|
|
|
|
|
/// </summary>
|
2020-11-18 17:40:23 +00:00
|
|
|
public static IUmbracoBuilder AddUmbraco(
|
|
|
|
|
this IServiceCollection services,
|
2020-11-19 16:20:39 +00:00
|
|
|
IWebHostEnvironment webHostEnvironment,
|
2020-11-20 12:24:16 +00:00
|
|
|
IConfiguration config)
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
if (services is null)
|
2020-12-08 11:08:14 +11:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
throw new ArgumentNullException(nameof(services));
|
2020-12-08 11:08:14 +11:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (config is null)
|
2020-12-08 11:08:14 +11:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
throw new ArgumentNullException(nameof(config));
|
2020-12-08 11:08:14 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IHostingEnvironment tempHostingEnvironment = GetTemporaryHostingEnvironment(webHostEnvironment, config);
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2021-03-03 10:40:16 +11:00
|
|
|
var loggingDir = tempHostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.LogFiles);
|
2020-12-08 11:08:14 +11:00
|
|
|
var loggingConfig = new LoggingConfiguration(loggingDir);
|
2020-11-23 10:27:13 +00:00
|
|
|
|
2020-11-24 09:22:38 +00:00
|
|
|
services.AddLogger(tempHostingEnvironment, loggingConfig, config);
|
2020-11-19 16:20:39 +00:00
|
|
|
|
2021-09-17 20:20:36 +02:00
|
|
|
// The DataDirectory is used to resolve database file paths (directly supported by SQL CE and manually replaced for LocalDB)
|
|
|
|
|
AppDomain.CurrentDomain.SetData("DataDirectory", tempHostingEnvironment?.MapPathContentRoot(Constants.SystemDirectories.Data));
|
|
|
|
|
|
2021-03-09 12:45:51 +11:00
|
|
|
// Manually create and register the HttpContextAccessor. In theory this should not be registered
|
|
|
|
|
// again by the user but if that is the case it's not the end of the world since HttpContextAccessor
|
|
|
|
|
// is just based on AsyncLocal, see https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http/src/HttpContextAccessor.cs
|
2020-11-20 11:48:32 +00:00
|
|
|
IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();
|
2020-11-20 12:24:16 +00:00
|
|
|
services.AddSingleton(httpContextAccessor);
|
2020-11-20 11:48:32 +00:00
|
|
|
|
2021-03-03 10:40:16 +11:00
|
|
|
var requestCache = new HttpContextRequestAppCache(httpContextAccessor);
|
2021-08-05 21:42:36 +02:00
|
|
|
var appCaches = AppCaches.Create(requestCache);
|
2020-11-20 11:48:32 +00:00
|
|
|
|
2021-09-08 13:41:46 +02:00
|
|
|
services.ConfigureOptions<ConfigureKestrelServerOptions>();
|
|
|
|
|
services.ConfigureOptions<ConfigureIISServerOptions>();
|
2021-09-09 11:39:47 +02:00
|
|
|
services.ConfigureOptions<ConfigureFormOptions>();
|
2021-09-08 13:41:46 +02:00
|
|
|
|
2020-12-08 11:08:14 +11:00
|
|
|
IProfiler profiler = GetWebProfiler(config);
|
2021-08-05 21:42:36 +02:00
|
|
|
|
2020-12-08 11:08:14 +11:00
|
|
|
ILoggerFactory loggerFactory = LoggerFactory.Create(cfg => cfg.AddSerilog(Log.Logger, false));
|
2021-07-09 16:15:37 -06:00
|
|
|
|
|
|
|
|
TypeLoader typeLoader = services.AddTypeLoader(
|
|
|
|
|
Assembly.GetEntryAssembly(),
|
|
|
|
|
tempHostingEnvironment,
|
|
|
|
|
loggerFactory,
|
|
|
|
|
appCaches,
|
|
|
|
|
config,
|
|
|
|
|
profiler);
|
2020-11-20 11:11:52 +00:00
|
|
|
|
2021-02-15 18:50:16 +11:00
|
|
|
// adds the umbraco startup filter which will call UseUmbraco early on before
|
|
|
|
|
// other start filters are applied (depending on the ordering of IStartupFilters in DI).
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
services.AddTransient<IStartupFilter, UmbracoApplicationServicesCapture>();
|
2021-02-15 18:50:16 +11:00
|
|
|
|
2021-07-09 15:31:01 -06:00
|
|
|
return new UmbracoBuilder(services, config, typeLoader, loggerFactory, profiler, appCaches, tempHostingEnvironment);
|
2020-09-02 18:10:29 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds core Umbraco services
|
|
|
|
|
/// </summary>
|
2020-12-24 16:35:59 +11:00
|
|
|
/// <remarks>
|
|
|
|
|
/// This will not add any composers/components
|
|
|
|
|
/// </remarks>
|
2020-11-20 12:24:16 +00:00
|
|
|
public static IUmbracoBuilder AddUmbracoCore(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
if (builder is null)
|
2020-12-23 12:02:01 +11:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
throw new ArgumentNullException(nameof(builder));
|
2020-12-23 12:02:01 +11:00
|
|
|
}
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
// Add ASP.NET specific services
|
|
|
|
|
builder.Services.AddUnique<IBackOfficeInfo, AspNetCoreBackOfficeInfo>();
|
|
|
|
|
builder.Services.AddUnique<IHostingEnvironment, AspNetCoreHostingEnvironment>();
|
|
|
|
|
builder.Services.AddHostedService(factory => factory.GetRequiredService<IRuntime>());
|
2020-11-20 12:24:16 +00:00
|
|
|
|
|
|
|
|
// Add supported databases
|
2020-11-23 12:04:40 +00:00
|
|
|
builder.AddUmbracoSqlServerSupport();
|
2021-01-11 09:04:05 +01:00
|
|
|
builder.AddUmbracoSqlCeSupport();
|
2021-01-18 15:40:22 +01:00
|
|
|
builder.Services.AddUnique<DatabaseSchemaCreatorFactory>();
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
// Must be added here because DbProviderFactories is netstandard 2.1 so cannot exist in Infra for now
|
2020-11-23 12:04:40 +00:00
|
|
|
builder.Services.AddSingleton<IDbProviderFactoryCreator>(factory => new DbProviderFactoryCreator(
|
2020-11-20 12:24:16 +00:00
|
|
|
DbProviderFactories.GetFactory,
|
2020-11-23 12:04:40 +00:00
|
|
|
factory.GetServices<ISqlSyntaxProvider>(),
|
|
|
|
|
factory.GetServices<IBulkSqlInsertProvider>(),
|
2021-09-17 12:02:41 +02:00
|
|
|
factory.GetServices<IDatabaseCreator>(),
|
2021-07-05 08:24:44 +02:00
|
|
|
factory.GetServices<IProviderSpecificMapperFactory>()
|
2020-11-23 12:04:40 +00:00
|
|
|
));
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-12-15 21:47:15 +00:00
|
|
|
builder.AddCoreInitialServices();
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-12-24 16:35:59 +11:00
|
|
|
// aspnet app lifetime mgmt
|
2021-01-12 13:58:48 +01:00
|
|
|
builder.Services.AddUnique<IUmbracoApplicationLifetime, AspNetCoreUmbracoApplicationLifetime>();
|
2020-12-24 16:35:59 +11:00
|
|
|
builder.Services.AddUnique<IApplicationShutdownRegistry, AspNetCoreApplicationShutdownRegistry>();
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-10-30 13:56:13 +01:00
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Add Umbraco hosted services
|
|
|
|
|
/// </summary>
|
2020-11-19 09:06:04 +00:00
|
|
|
public static IUmbracoBuilder AddHostedServices(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
2021-01-25 09:26:38 +01:00
|
|
|
builder.Services.AddHostedService<QueuedHostedService>();
|
2020-11-20 12:24:16 +00:00
|
|
|
builder.Services.AddHostedService<HealthCheckNotifier>();
|
|
|
|
|
builder.Services.AddHostedService<KeepAlive>();
|
|
|
|
|
builder.Services.AddHostedService<LogScrubber>();
|
|
|
|
|
builder.Services.AddHostedService<ScheduledPublishing>();
|
|
|
|
|
builder.Services.AddHostedService<TempFileCleanup>();
|
|
|
|
|
builder.Services.AddHostedService<InstructionProcessTask>();
|
|
|
|
|
builder.Services.AddHostedService<TouchServerTask>();
|
2020-12-07 11:56:38 +01:00
|
|
|
builder.Services.AddHostedService<ReportSiteTask>();
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
private static IUmbracoBuilder AddHttpClients(this IUmbracoBuilder builder)
|
2020-11-19 09:06:04 +00:00
|
|
|
{
|
2020-11-20 12:24:16 +00:00
|
|
|
builder.Services.AddHttpClient();
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
/// <summary>
|
2021-01-12 13:58:48 +01:00
|
|
|
/// Adds the Umbraco request profiler
|
2020-12-23 12:02:01 +11:00
|
|
|
/// </summary>
|
2021-01-12 13:58:48 +01:00
|
|
|
public static IUmbracoBuilder AddUmbracoProfiler(this IUmbracoBuilder builder)
|
2020-11-19 09:06:04 +00:00
|
|
|
{
|
2021-01-12 13:58:48 +01:00
|
|
|
builder.Services.AddUnique<WebProfilerHtml>();
|
|
|
|
|
|
2020-09-02 18:10:29 +10:00
|
|
|
builder.Services.AddMiniProfiler(options =>
|
2021-03-05 15:36:27 +01:00
|
|
|
{
|
2020-12-23 12:02:01 +11:00
|
|
|
// WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile
|
2021-03-05 15:36:27 +01:00
|
|
|
options.ShouldProfile = request => false;
|
|
|
|
|
|
|
|
|
|
// this is a default path and by default it performs a 'contains' check which will match our content controller
|
|
|
|
|
// (and probably other requests) and ignore them.
|
|
|
|
|
options.IgnoredPaths.Remove("/content/");
|
|
|
|
|
});
|
2020-11-19 09:06:04 +00:00
|
|
|
|
2021-05-11 14:33:49 +02:00
|
|
|
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, InitializeWebProfiling>();
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-09-17 09:01:10 +02:00
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
public static IUmbracoBuilder AddMvcAndRazor(this IUmbracoBuilder builder, Action<IMvcBuilder> mvcBuilding = null)
|
2020-11-19 09:06:04 +00:00
|
|
|
{
|
|
|
|
|
// TODO: We need to figure out if we can work around this because calling AddControllersWithViews modifies the global app and order is very important
|
|
|
|
|
// this will directly affect developers who need to call that themselves.
|
2020-12-22 12:16:37 +11:00
|
|
|
// We need to have runtime compilation of views when using umbraco. We could consider having only this when a specific config is set.
|
|
|
|
|
// But as far as I can see, there are still precompiled views, even when this is activated, so maybe it is okay.
|
2020-12-23 12:02:01 +11:00
|
|
|
IMvcBuilder mvcBuilder = builder.Services
|
|
|
|
|
.AddControllersWithViews()
|
|
|
|
|
.AddRazorRuntimeCompilation();
|
2020-10-15 11:42:16 +02:00
|
|
|
|
2020-11-19 09:06:04 +00:00
|
|
|
mvcBuilding?.Invoke(mvcBuilder);
|
2020-10-15 11:42:16 +02:00
|
|
|
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-10-15 11:42:16 +02:00
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Add runtime minifier support for Umbraco
|
|
|
|
|
/// </summary>
|
2021-03-16 19:19:03 +11:00
|
|
|
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
|
2020-11-19 09:06:04 +00:00
|
|
|
{
|
2021-03-16 19:19:03 +11:00
|
|
|
// Add custom ISmidgeFileProvider to include the additional App_Plugins location
|
|
|
|
|
// to load assets from.
|
|
|
|
|
builder.Services.AddSingleton<ISmidgeFileProvider>(f =>
|
|
|
|
|
{
|
|
|
|
|
IWebHostEnvironment hostEnv = f.GetRequiredService<IWebHostEnvironment>();
|
|
|
|
|
|
|
|
|
|
return new SmidgeFileProvider(
|
|
|
|
|
hostEnv.WebRootFileProvider,
|
|
|
|
|
new GlobPatternFilterFileProvider(
|
|
|
|
|
hostEnv.ContentRootFileProvider,
|
|
|
|
|
// only include js or css files within App_Plugins
|
2021-03-17 17:44:52 +11:00
|
|
|
new[] { "/App_Plugins/**/*.js", "/App_Plugins/**/*.css" }));
|
2021-03-16 19:19:03 +11:00
|
|
|
});
|
2021-02-18 14:07:07 +01:00
|
|
|
|
2021-03-16 17:15:40 +11:00
|
|
|
builder.Services.AddSmidge(builder.Config.GetSection(Constants.Configuration.ConfigRuntimeMinification));
|
2020-11-19 09:06:04 +00:00
|
|
|
builder.Services.AddSmidgeNuglify();
|
2021-03-17 17:44:52 +11:00
|
|
|
builder.Services.AddSmidgeInMemory(false); // it will be enabled based on config/cachebuster
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IRuntimeMinifier, SmidgeRuntimeMinifier>();
|
|
|
|
|
builder.Services.AddUnique<SmidgeHelperAccessor>();
|
|
|
|
|
builder.Services.AddTransient<IPreProcessor, SmidgeNuglifyJs>();
|
|
|
|
|
builder.Services.ConfigureOptions<SmidgeOptionsSetup>();
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds all web based services required for Umbraco to run
|
|
|
|
|
/// </summary>
|
2020-11-19 09:06:04 +00:00
|
|
|
public static IUmbracoBuilder AddWebComponents(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
2020-11-24 09:22:38 +00: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
|
|
|
|
|
builder.Services.AddSession(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Cookie.Name = "UMB_SESSION";
|
|
|
|
|
options.Cookie.HttpOnly = true;
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
builder.Services.ConfigureOptions<UmbracoMvcConfigureOptions>();
|
2021-01-08 11:29:07 +11:00
|
|
|
builder.Services.ConfigureOptions<UmbracoRequestLocalizationOptions>();
|
2020-11-19 09:06:04 +00:00
|
|
|
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, UmbracoApiBehaviorApplicationModelProvider>());
|
|
|
|
|
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, BackOfficeApplicationModelProvider>());
|
2021-02-15 18:50:16 +11:00
|
|
|
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IApplicationModelProvider, VirtualPageApplicationModelProvider>());
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
builder.AddUmbracoImageSharp();
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
// AspNetCore specific services
|
|
|
|
|
builder.Services.AddUnique<IRequestAccessor, AspNetCoreRequestAccessor>();
|
2021-05-11 14:33:49 +02:00
|
|
|
builder.AddNotificationHandler<UmbracoRequestBeginNotification, AspNetCoreRequestAccessor>();
|
2020-12-24 14:29:26 +11:00
|
|
|
|
|
|
|
|
// Password hasher
|
|
|
|
|
builder.Services.AddUnique<IPasswordHasher, AspNetCorePasswordHasher>();
|
|
|
|
|
|
2021-04-09 15:24:12 +10:00
|
|
|
builder.Services.AddUnique<Cms.Core.Web.ICookieManager, AspNetCoreCookieManager>();
|
2020-12-24 14:29:26 +11:00
|
|
|
builder.Services.AddTransient<IIpResolver, AspNetCoreIpResolver>();
|
|
|
|
|
builder.Services.AddUnique<IUserAgentProvider, AspNetCoreUserAgentProvider>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddMultipleUnique<ISessionIdResolver, ISessionManager, AspNetCoreSessionManager>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IMarchal, AspNetCoreMarchal>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IProfilerHtml, WebProfilerHtml>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IMacroRenderer, MacroRenderer>();
|
2021-02-26 16:53:53 +11:00
|
|
|
builder.Services.AddUnique<PartialViewMacroEngine>();
|
2020-12-24 14:29:26 +11:00
|
|
|
|
|
|
|
|
// register the umbraco context factory
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IUmbracoContextFactory, UmbracoContextFactory>();
|
2021-03-03 10:40:16 +11:00
|
|
|
builder.Services.AddUnique<IBackOfficeSecurityAccessor, BackOfficeSecurityAccessor>();
|
2020-12-24 14:29:26 +11:00
|
|
|
|
|
|
|
|
var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList();
|
|
|
|
|
builder.WithCollectionBuilder<UmbracoApiControllerTypeCollectionBuilder>()
|
|
|
|
|
.Add(umbracoApiControllerTypes);
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<UmbracoRequestLoggingMiddleware>();
|
2021-02-19 11:45:58 +01:00
|
|
|
builder.Services.AddUnique<PreviewAuthenticationMiddleware>();
|
2020-12-24 14:29:26 +11:00
|
|
|
builder.Services.AddUnique<UmbracoRequestMiddleware>();
|
|
|
|
|
builder.Services.AddUnique<BootFailedMiddleware>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<UmbracoJsonModelBinder>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<ITemplateRenderer, TemplateRenderer>();
|
|
|
|
|
builder.Services.AddUnique<IPublicAccessChecker, PublicAccessChecker>();
|
|
|
|
|
|
2021-01-15 18:17:13 +11:00
|
|
|
builder.Services.AddSingleton<ContentModelBinder>();
|
|
|
|
|
|
2021-08-04 12:48:19 +02:00
|
|
|
builder.Services.AddSingleton<IUmbracoHelperAccessor, UmbracoHelperAccessor>();
|
2021-01-29 10:30:28 +01:00
|
|
|
builder.Services.AddScoped<UmbracoHelper>();
|
2021-03-04 15:07:54 +11:00
|
|
|
builder.Services.AddScoped<IBackOfficeSecurity, BackOfficeSecurity>();
|
2021-01-29 10:30:28 +01:00
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
builder.AddHttpClients();
|
|
|
|
|
|
2020-11-19 09:06:04 +00:00
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 16:31:17 +00:00
|
|
|
|
2020-12-23 12:02:01 +11:00
|
|
|
// TODO: Does this need to exist and/or be public?
|
2020-11-19 09:06:04 +00:00
|
|
|
public static IUmbracoBuilder AddWebServer(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
2020-12-23 12:02:01 +11:00
|
|
|
// TODO: We need to figure out why this is needed and fix those endpoints to not need them, we don't want to change global things
|
2020-11-19 09:06:04 +00:00
|
|
|
// If using Kestrel: https://stackoverflow.com/a/55196057
|
|
|
|
|
builder.Services.Configure<KestrelServerOptions>(options =>
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
2020-11-19 09:06:04 +00:00
|
|
|
options.AllowSynchronousIO = true;
|
2020-09-02 18:10:29 +10:00
|
|
|
});
|
2020-11-19 09:06:04 +00:00
|
|
|
builder.Services.Configure<IISServerOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AllowSynchronousIO = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2020-11-20 12:24:16 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds SqlCe support for Umbraco
|
|
|
|
|
/// </summary>
|
2020-11-23 12:04:40 +00:00
|
|
|
private static IUmbracoBuilder AddUmbracoSqlCeSupport(this IUmbracoBuilder builder)
|
2020-11-20 12:24:16 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var binFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
if (binFolder != null)
|
|
|
|
|
{
|
2021-01-20 21:01:45 +01:00
|
|
|
var dllPath = Path.Combine(binFolder, "Umbraco.Persistence.SqlCe.dll");
|
2020-11-20 12:24:16 +00:00
|
|
|
var umbSqlCeAssembly = Assembly.LoadFrom(dllPath);
|
|
|
|
|
|
2021-06-24 09:43:57 -06:00
|
|
|
Type sqlCeSyntaxProviderType = umbSqlCeAssembly.GetType("Umbraco.Cms.Persistence.SqlCe.SqlCeSyntaxProvider");
|
|
|
|
|
Type sqlCeBulkSqlInsertProviderType = umbSqlCeAssembly.GetType("Umbraco.Cms.Persistence.SqlCe.SqlCeBulkSqlInsertProvider");
|
2021-09-17 12:02:41 +02:00
|
|
|
Type sqlCeDatabaseCreatorType = umbSqlCeAssembly.GetType("Umbraco.Cms.Persistence.SqlCe.SqlCeDatabaseCreator");
|
2021-07-05 08:24:44 +02:00
|
|
|
Type sqlCeSpecificMapperFactory = umbSqlCeAssembly.GetType("Umbraco.Cms.Persistence.SqlCe.SqlCeSpecificMapperFactory");
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2021-07-05 08:24:44 +02:00
|
|
|
if (!(sqlCeSyntaxProviderType is null
|
|
|
|
|
|| sqlCeBulkSqlInsertProviderType is null
|
2021-09-17 12:02:41 +02:00
|
|
|
|| sqlCeDatabaseCreatorType is null
|
2021-07-05 08:24:44 +02:00
|
|
|
|| sqlCeSpecificMapperFactory is null))
|
2020-11-20 12:24:16 +00:00
|
|
|
{
|
2020-11-23 12:04:40 +00:00
|
|
|
builder.Services.AddSingleton(typeof(ISqlSyntaxProvider), sqlCeSyntaxProviderType);
|
|
|
|
|
builder.Services.AddSingleton(typeof(IBulkSqlInsertProvider), sqlCeBulkSqlInsertProviderType);
|
2021-09-17 12:02:41 +02:00
|
|
|
builder.Services.AddSingleton(typeof(IDatabaseCreator), sqlCeDatabaseCreatorType);
|
2021-07-05 08:24:44 +02:00
|
|
|
builder.Services.AddSingleton(typeof(IProviderSpecificMapperFactory), sqlCeSpecificMapperFactory);
|
2020-11-20 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sqlCeAssembly = Assembly.LoadFrom(Path.Combine(binFolder, "System.Data.SqlServerCe.dll"));
|
|
|
|
|
|
|
|
|
|
var sqlCe = sqlCeAssembly.GetType("System.Data.SqlServerCe.SqlCeProviderFactory");
|
|
|
|
|
if (!(sqlCe is null))
|
|
|
|
|
{
|
2021-02-09 10:22:42 +01:00
|
|
|
DbProviderFactories.RegisterFactory(Cms.Core.Constants.DbProviderNames.SqlCe, sqlCe);
|
2020-11-20 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore if SqlCE is not available
|
|
|
|
|
}
|
2020-11-23 12:04:40 +00:00
|
|
|
|
|
|
|
|
return builder;
|
2020-11-20 12:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds Sql Server support for Umbraco
|
|
|
|
|
/// </summary>
|
2020-11-23 12:04:40 +00:00
|
|
|
private static IUmbracoBuilder AddUmbracoSqlServerSupport(this IUmbracoBuilder builder)
|
2020-11-20 12:24:16 +00:00
|
|
|
{
|
2021-02-09 10:22:42 +01:00
|
|
|
DbProviderFactories.RegisterFactory(Cms.Core.Constants.DbProviderNames.SqlServer, SqlClientFactory.Instance);
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-11-23 12:04:40 +00:00
|
|
|
builder.Services.AddSingleton<ISqlSyntaxProvider, SqlServerSyntaxProvider>();
|
|
|
|
|
builder.Services.AddSingleton<IBulkSqlInsertProvider, SqlServerBulkSqlInsertProvider>();
|
2021-09-17 12:02:41 +02:00
|
|
|
builder.Services.AddSingleton<IDatabaseCreator, SqlServerDatabaseCreator>();
|
2020-11-20 12:24:16 +00:00
|
|
|
|
2020-11-23 12:04:40 +00:00
|
|
|
return builder;
|
2020-11-20 12:24:16 +00:00
|
|
|
}
|
2020-11-24 09:22:38 +00:00
|
|
|
|
|
|
|
|
private static IProfiler GetWebProfiler(IConfiguration config)
|
|
|
|
|
{
|
2021-02-09 10:22:42 +01:00
|
|
|
var isDebug = config.GetValue<bool>($"{Cms.Core.Constants.Configuration.ConfigHosting}:Debug");
|
2020-11-24 09:22:38 +00:00
|
|
|
// create and start asap to profile boot
|
|
|
|
|
if (!isDebug)
|
|
|
|
|
{
|
|
|
|
|
// 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
|
2020-12-24 16:35:59 +11:00
|
|
|
return new NoopProfiler();
|
2020-11-24 09:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var webProfiler = new WebProfiler();
|
|
|
|
|
webProfiler.StartBoot();
|
|
|
|
|
|
|
|
|
|
return webProfiler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// HACK: returns an AspNetCoreHostingEnvironment that doesn't monitor changes to configuration.<br/>
|
|
|
|
|
/// We require this to create a TypeLoader during ConfigureServices.<br/>
|
|
|
|
|
/// Instances returned from this method shouldn't be registered in the service collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static IHostingEnvironment GetTemporaryHostingEnvironment(IWebHostEnvironment webHostEnvironment, IConfiguration config)
|
|
|
|
|
{
|
2021-02-09 10:22:42 +01:00
|
|
|
var hostingSettings = config.GetSection(Cms.Core.Constants.Configuration.ConfigHosting).Get<HostingSettings>() ?? new HostingSettings();
|
|
|
|
|
var webRoutingSettings = config.GetSection(Cms.Core.Constants.Configuration.ConfigWebRouting).Get<WebRoutingSettings>() ?? new WebRoutingSettings();
|
2020-11-24 09:22:38 +00:00
|
|
|
var wrappedHostingSettings = new OptionsMonitorAdapter<HostingSettings>(hostingSettings);
|
2021-02-08 11:00:15 +01:00
|
|
|
var wrappedWebRoutingSettings = new OptionsMonitorAdapter<WebRoutingSettings>(webRoutingSettings);
|
2020-11-24 09:22:38 +00:00
|
|
|
|
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
|
|
|
// This is needed in order to create a unique Application Id
|
|
|
|
|
var serviceCollection = new ServiceCollection();
|
|
|
|
|
serviceCollection.AddDataProtection();
|
|
|
|
|
serviceCollection.AddSingleton<IHostEnvironment>(s => webHostEnvironment);
|
|
|
|
|
var serviceProvider = serviceCollection.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
return new AspNetCoreHostingEnvironment(
|
|
|
|
|
serviceProvider,
|
|
|
|
|
wrappedHostingSettings,
|
|
|
|
|
wrappedWebRoutingSettings,
|
|
|
|
|
webHostEnvironment);
|
2020-11-24 09:22:38 +00:00
|
|
|
}
|
2021-02-18 14:07:07 +01:00
|
|
|
|
2020-09-02 18:10:29 +10:00
|
|
|
}
|
|
|
|
|
}
|