2020-12-03 13:32:04 +00:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-12-24 11:46:17 +11:00
|
|
|
using System.Runtime.InteropServices;
|
2020-12-03 13:32:04 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-09-02 18:10:29 +10:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-19 16:20:39 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
2020-12-24 16:35:59 +11:00
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Composing;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Grid;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Diagnostics;
|
|
|
|
|
using Umbraco.Cms.Core.Dictionary;
|
|
|
|
|
using Umbraco.Cms.Core.Editors;
|
|
|
|
|
using Umbraco.Cms.Core.Events;
|
|
|
|
|
using Umbraco.Cms.Core.Features;
|
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
|
|
|
using Umbraco.Cms.Core.Handlers;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
using Umbraco.Cms.Core.Install;
|
|
|
|
|
using Umbraco.Cms.Core.IO;
|
|
|
|
|
using Umbraco.Cms.Core.Logging;
|
|
|
|
|
using Umbraco.Cms.Core.Mail;
|
|
|
|
|
using Umbraco.Cms.Core.Manifest;
|
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
2021-05-11 14:33:49 +02:00
|
|
|
using Umbraco.Cms.Core.Notifications;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.PropertyEditors;
|
2021-06-24 10:25:23 -06:00
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache.Internal;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Routing;
|
|
|
|
|
using Umbraco.Cms.Core.Runtime;
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Sync;
|
|
|
|
|
using Umbraco.Cms.Core.Templates;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
2021-10-06 11:13:59 +02:00
|
|
|
using Umbraco.Cms.Web.Common.DependencyInjection;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Extensions;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Core.DependencyInjection
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
|
|
|
|
public class UmbracoBuilder : IUmbracoBuilder
|
|
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
private readonly Dictionary<Type, ICollectionBuilder> _builders = new Dictionary<Type, ICollectionBuilder>();
|
|
|
|
|
|
2020-11-24 09:22:38 +00:00
|
|
|
public IServiceCollection Services { get; }
|
2020-12-24 09:50:05 +11:00
|
|
|
|
2020-11-24 09:22:38 +00:00
|
|
|
public IConfiguration Config { get; }
|
2020-12-24 09:50:05 +11:00
|
|
|
|
2020-11-24 09:22:38 +00:00
|
|
|
public TypeLoader TypeLoader { get; }
|
|
|
|
|
|
2021-07-09 15:31:01 -06:00
|
|
|
/// <inheritdoc />
|
2020-12-24 09:50:05 +11:00
|
|
|
public ILoggerFactory BuilderLoggerFactory { get; }
|
2020-09-02 18:10:29 +10:00
|
|
|
|
2021-07-09 15:31:01 -06:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public IHostingEnvironment BuilderHostingEnvironment { get; }
|
|
|
|
|
|
|
|
|
|
public IProfiler Profiler { get; }
|
|
|
|
|
|
|
|
|
|
public AppCaches AppCaches { get; }
|
|
|
|
|
|
2020-12-24 09:50:05 +11:00
|
|
|
/// <summary>
|
2021-07-09 15:31:01 -06:00
|
|
|
/// Initializes a new instance of the <see cref="UmbracoBuilder"/> class primarily for testing.
|
2020-12-24 09:50:05 +11:00
|
|
|
/// </summary>
|
2020-11-20 11:48:32 +00:00
|
|
|
public UmbracoBuilder(IServiceCollection services, IConfiguration config, TypeLoader typeLoader)
|
2021-07-09 15:31:01 -06:00
|
|
|
: this(services, config, typeLoader, NullLoggerFactory.Instance, new NoopProfiler(), AppCaches.Disabled, null)
|
2020-11-19 16:20:39 +00:00
|
|
|
{ }
|
|
|
|
|
|
2020-12-24 09:50:05 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UmbracoBuilder"/> class.
|
|
|
|
|
/// </summary>
|
2021-07-09 15:31:01 -06:00
|
|
|
public UmbracoBuilder(
|
|
|
|
|
IServiceCollection services,
|
|
|
|
|
IConfiguration config,
|
|
|
|
|
TypeLoader typeLoader,
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IProfiler profiler,
|
|
|
|
|
AppCaches appCaches,
|
|
|
|
|
IHostingEnvironment hostingEnvironment)
|
2020-09-02 18:10:29 +10:00
|
|
|
{
|
|
|
|
|
Services = services;
|
|
|
|
|
Config = config;
|
2020-11-19 16:20:39 +00:00
|
|
|
BuilderLoggerFactory = loggerFactory;
|
2021-07-09 15:31:01 -06:00
|
|
|
BuilderHostingEnvironment = hostingEnvironment;
|
|
|
|
|
Profiler = profiler;
|
|
|
|
|
AppCaches = appCaches;
|
2020-11-20 11:48:32 +00:00
|
|
|
TypeLoader = typeLoader;
|
2020-11-30 23:39:56 +00:00
|
|
|
|
|
|
|
|
AddCoreServices();
|
2020-09-02 18:10:29 +10:00
|
|
|
}
|
|
|
|
|
|
2020-11-18 10:41:20 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a collection builder (and registers the collection).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TBuilder">The type of the collection builder.</typeparam>
|
|
|
|
|
/// <returns>The collection builder.</returns>
|
|
|
|
|
public TBuilder WithCollectionBuilder<TBuilder>()
|
|
|
|
|
where TBuilder : ICollectionBuilder, new()
|
|
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
Type typeOfBuilder = typeof(TBuilder);
|
2020-11-18 10:41:20 +00:00
|
|
|
|
2020-12-24 09:50:05 +11:00
|
|
|
if (_builders.TryGetValue(typeOfBuilder, out ICollectionBuilder o))
|
|
|
|
|
{
|
2020-11-18 10:41:20 +00:00
|
|
|
return (TBuilder)o;
|
2020-12-24 09:50:05 +11:00
|
|
|
}
|
2020-11-18 10:41:20 +00:00
|
|
|
|
|
|
|
|
var builder = new TBuilder();
|
|
|
|
|
_builders[typeOfBuilder] = builder;
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:10:29 +10:00
|
|
|
public void Build()
|
|
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
foreach (ICollectionBuilder builder in _builders.Values)
|
|
|
|
|
{
|
2020-11-18 10:41:20 +00:00
|
|
|
builder.RegisterWith(Services);
|
2020-12-24 09:50:05 +11:00
|
|
|
}
|
2020-11-18 10:41:20 +00:00
|
|
|
|
|
|
|
|
_builders.Clear();
|
2020-09-02 18:10:29 +10:00
|
|
|
}
|
2020-11-30 23:39:56 +00:00
|
|
|
|
|
|
|
|
private void AddCoreServices()
|
|
|
|
|
{
|
2021-07-09 15:31:01 -06:00
|
|
|
Services.AddSingleton(AppCaches);
|
|
|
|
|
Services.AddSingleton(Profiler);
|
|
|
|
|
|
2020-12-01 12:09:50 +00:00
|
|
|
// Register as singleton to allow injection everywhere.
|
|
|
|
|
Services.AddSingleton<ServiceFactory>(p => p.GetService);
|
|
|
|
|
Services.AddSingleton<IEventAggregator, EventAggregator>();
|
2020-12-24 11:46:17 +11:00
|
|
|
|
|
|
|
|
Services.AddLazySupport();
|
|
|
|
|
|
2020-12-24 16:35:59 +11:00
|
|
|
// Adds no-op registrations as many core services require these dependencies but these
|
|
|
|
|
// dependencies cannot be fulfilled in the Core project
|
|
|
|
|
Services.AddUnique<IMarchal, NoopMarchal>();
|
|
|
|
|
Services.AddUnique<IApplicationShutdownRegistry, NoopApplicationShutdownRegistry>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<IMainDom, MainDom>();
|
2020-12-24 11:46:17 +11:00
|
|
|
Services.AddUnique<IMainDomLock, MainDomSemaphoreLock>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<IIOHelper>(factory =>
|
|
|
|
|
{
|
|
|
|
|
IHostingEnvironment hostingEnvironment = factory.GetRequiredService<IHostingEnvironment>();
|
|
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
return new IOHelperLinux(hostingEnvironment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
|
|
{
|
|
|
|
|
return new IOHelperOSX(hostingEnvironment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new IOHelperWindows(hostingEnvironment);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Services.AddUnique(factory => factory.GetRequiredService<AppCaches>().RuntimeCache);
|
|
|
|
|
Services.AddUnique(factory => factory.GetRequiredService<AppCaches>().RequestCache);
|
|
|
|
|
Services.AddUnique<IProfilingLogger, ProfilingLogger>();
|
|
|
|
|
Services.AddUnique<IUmbracoVersion, UmbracoVersion>();
|
|
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
this.AddAllCoreCollectionBuilders();
|
2021-05-11 14:33:49 +02:00
|
|
|
this.AddNotificationHandler<UmbracoApplicationStartingNotification, EssentialDirectoryCreator>();
|
2020-12-24 11:46:17 +11:00
|
|
|
|
2021-01-08 17:21:35 +11:00
|
|
|
Services.AddSingleton<UmbracoRequestPaths>();
|
2020-12-24 11:46:17 +11:00
|
|
|
|
|
|
|
|
Services.AddUnique<InstallStatusTracker>();
|
|
|
|
|
|
|
|
|
|
// by default, register a noop factory
|
|
|
|
|
Services.AddUnique<IPublishedModelFactory, NoopPublishedModelFactory>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<ICultureDictionaryFactory, DefaultCultureDictionaryFactory>();
|
|
|
|
|
Services.AddSingleton(f => f.GetRequiredService<ICultureDictionaryFactory>().CreateDictionary());
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<UriUtility>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<IDashboardService, DashboardService>();
|
|
|
|
|
|
|
|
|
|
// will be injected in controllers when needed to invoke rest endpoints on Our
|
|
|
|
|
Services.AddUnique<IInstallationService, InstallationService>();
|
|
|
|
|
Services.AddUnique<IUpgradeService, UpgradeService>();
|
|
|
|
|
|
|
|
|
|
// Grid config is not a real config file as we know them
|
|
|
|
|
Services.AddUnique<IGridConfig, GridConfig>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<IPublishedUrlProvider, UrlProvider>();
|
2021-04-22 20:25:25 +10:00
|
|
|
Services.AddUnique<ISiteDomainMapper, SiteDomainMapper>();
|
2020-12-24 11:46:17 +11:00
|
|
|
|
|
|
|
|
Services.AddUnique<HtmlLocalLinkParser>();
|
|
|
|
|
Services.AddUnique<HtmlImageSourceParser>();
|
|
|
|
|
Services.AddUnique<HtmlUrlParser>();
|
|
|
|
|
|
|
|
|
|
// register properties fallback
|
|
|
|
|
Services.AddUnique<IPublishedValueFallback, PublishedValueFallback>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<UmbracoFeatures>();
|
|
|
|
|
|
|
|
|
|
// register published router
|
|
|
|
|
Services.AddUnique<IPublishedRouter, PublishedRouter>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<IEventMessagesFactory, DefaultEventMessagesFactory>();
|
|
|
|
|
Services.AddUnique<IEventMessagesAccessor, HybridEventMessagesAccessor>();
|
|
|
|
|
Services.AddUnique<ITreeService, TreeService>();
|
|
|
|
|
Services.AddUnique<ISectionService, SectionService>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<ISmsSender, NotImplementedSmsSender>();
|
|
|
|
|
Services.AddUnique<IEmailSender, NotImplementedEmailSender>();
|
|
|
|
|
|
2021-05-18 12:40:24 +02:00
|
|
|
Services.AddUnique<IDataValueEditorFactory, DataValueEditorFactory>();
|
|
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
// register distributed cache
|
|
|
|
|
Services.AddUnique(f => new DistributedCache(f.GetRequiredService<IServerMessenger>(), f.GetRequiredService<CacheRefresherCollection>()));
|
2021-03-15 13:39:34 +11:00
|
|
|
Services.AddUnique<ICacheRefresherNotificationFactory, CacheRefresherNotificationFactory>();
|
2020-12-24 11:46:17 +11:00
|
|
|
|
|
|
|
|
// register the http context and umbraco context accessors
|
|
|
|
|
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
|
|
|
|
|
// we have no http context, eg when booting Umbraco or in background threads, so instead
|
|
|
|
|
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
|
|
|
|
|
Services.AddUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
|
|
|
|
|
|
|
|
|
|
Services.AddUnique<LegacyPasswordSecurity>();
|
|
|
|
|
Services.AddUnique<UserEditorAuthorizationHelper>();
|
|
|
|
|
Services.AddUnique<ContentPermissions>();
|
|
|
|
|
Services.AddUnique<MediaPermissions>();
|
2020-12-24 14:29:26 +11:00
|
|
|
|
|
|
|
|
Services.AddUnique<PropertyEditorCollection>();
|
|
|
|
|
Services.AddUnique<ParameterEditorCollection>();
|
2020-12-24 16:35:59 +11:00
|
|
|
|
|
|
|
|
// register a server registrar, by default it's the db registrar
|
|
|
|
|
Services.AddUnique<IServerRoleAccessor>(f =>
|
|
|
|
|
{
|
|
|
|
|
GlobalSettings globalSettings = f.GetRequiredService<IOptions<GlobalSettings>>().Value;
|
|
|
|
|
var singleServer = globalSettings.DisableElectionForSingleServer;
|
|
|
|
|
return singleServer
|
|
|
|
|
? (IServerRoleAccessor)new SingleServerRoleAccessor()
|
|
|
|
|
: new ElectedServerRoleAccessor(f.GetRequiredService<IServerRegistrationService>());
|
|
|
|
|
});
|
2021-02-01 16:53:24 +11:00
|
|
|
|
|
|
|
|
// For Umbraco to work it must have the default IPublishedModelFactory
|
|
|
|
|
// which may be replaced by models builder but the default is required to make plain old IPublishedContent
|
|
|
|
|
// instances.
|
|
|
|
|
Services.AddSingleton<IPublishedModelFactory>(factory => factory.CreateDefaultPublishedModelFactory());
|
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
|
|
|
|
|
.AddNotificationHandler<MemberGroupSavedNotification, PublicAccessHandler>()
|
|
|
|
|
.AddNotificationHandler<MemberGroupDeletedNotification, PublicAccessHandler>();
|
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
|
|
|
|
|
|
|
|
Services.AddSingleton<ISyncBootStateAccessor, NonRuntimeLevelBootStateAccessor>();
|
2021-06-24 10:25:23 -06:00
|
|
|
|
|
|
|
|
// register a basic/noop published snapshot service to be replaced
|
|
|
|
|
Services.AddSingleton<IPublishedSnapshotService, InternalPublishedSnapshotService>();
|
2021-08-23 14:28:44 +02:00
|
|
|
|
|
|
|
|
// Register ValueEditorCache used for validation
|
|
|
|
|
Services.AddSingleton<IValueEditorCache, ValueEditorCache>();
|
2020-11-30 23:39:56 +00:00
|
|
|
}
|
2020-09-02 18:10:29 +10:00
|
|
|
}
|
|
|
|
|
}
|