diff --git a/src/Umbraco.Core/Composing/ComponentComposer.cs b/src/Umbraco.Core/Composing/ComponentComposer.cs
index 8092b58c79..853d4f4502 100644
--- a/src/Umbraco.Core/Composing/ComponentComposer.cs
+++ b/src/Umbraco.Core/Composing/ComponentComposer.cs
@@ -1,5 +1,5 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Core.Composing
{
diff --git a/src/Umbraco.Core/Composing/Composers.cs b/src/Umbraco.Core/Composing/Composers.cs
index caef92f90a..47f272cbf4 100644
--- a/src/Umbraco.Core/Composing/Composers.cs
+++ b/src/Umbraco.Core/Composing/Composers.cs
@@ -6,7 +6,7 @@ using System.Text;
using Umbraco.Core.Collections;
using Umbraco.Core.Logging;
using Microsoft.Extensions.Logging;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Core.Composing
{
diff --git a/src/Umbraco.Core/Composing/CompositionExtensions.cs b/src/Umbraco.Core/Composing/CompositionExtensions.cs
index ff99142c2c..e4e02443eb 100644
--- a/src/Umbraco.Core/Composing/CompositionExtensions.cs
+++ b/src/Umbraco.Core/Composing/CompositionExtensions.cs
@@ -1,6 +1,6 @@
using System;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Web.PublishedCache;
diff --git a/src/Umbraco.Core/Composing/IComposer.cs b/src/Umbraco.Core/Composing/IComposer.cs
index 6ba21eff4e..d67bb71461 100644
--- a/src/Umbraco.Core/Composing/IComposer.cs
+++ b/src/Umbraco.Core/Composing/IComposer.cs
@@ -1,4 +1,4 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Core.Composing
{
diff --git a/src/Umbraco.Core/CompositionExtensions.cs b/src/Umbraco.Core/CompositionExtensions.cs
index 716f53a383..58aac7b811 100644
--- a/src/Umbraco.Core/CompositionExtensions.cs
+++ b/src/Umbraco.Core/CompositionExtensions.cs
@@ -1,4 +1,4 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.HealthCheck;
using Umbraco.Core.Manifest;
diff --git a/src/Umbraco.Core/Builder/IUmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs
similarity index 84%
rename from src/Umbraco.Core/Builder/IUmbracoBuilder.cs
rename to src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs
index 4659be55f1..f532f8cdaa 100644
--- a/src/Umbraco.Core/Builder/IUmbracoBuilder.cs
+++ b/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs
@@ -1,9 +1,9 @@
-using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Core.Composing;
-namespace Umbraco.Core.Builder
+namespace Umbraco.Core.DependencyInjection
{
public interface IUmbracoBuilder
{
diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Events.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Events.cs
new file mode 100644
index 0000000000..a21ae74976
--- /dev/null
+++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Events.cs
@@ -0,0 +1,30 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using Microsoft.Extensions.DependencyInjection;
+using Umbraco.Core.Events;
+
+namespace Umbraco.Core.DependencyInjection
+{
+ ///
+ /// Contains extensions methods for used for registering event handlers.
+ ///
+ public static partial class UmbracoBuilderExtensions
+ {
+ ///
+ /// Registers a notification handler against the Umbraco service collection.
+ ///
+ /// The type of notification.
+ /// The type of notificiation handler.
+ /// The Umbraco builder.
+ /// The .
+ public static IUmbracoBuilder AddNotificationHandler(this IUmbracoBuilder builder)
+ where TNotificationHandler : INotificationHandler
+ where TNotification : INotification
+ {
+ // Register the handler as transient. This ensures that anything can be injected into it.
+ builder.Services.AddTransient(typeof(INotificationHandler), typeof(TNotificationHandler));
+ return builder;
+ }
+ }
+}
diff --git a/src/Umbraco.Core/Builder/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
similarity index 80%
rename from src/Umbraco.Core/Builder/UmbracoBuilder.cs
rename to src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
index 9514b0de59..d56712cdcf 100644
--- a/src/Umbraco.Core/Builder/UmbracoBuilder.cs
+++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
@@ -1,13 +1,16 @@
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
using System;
using System.Collections.Generic;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
-using Umbraco.Core.Builder;
using Umbraco.Core.Composing;
+using Umbraco.Core.Events;
-namespace Umbraco.Web.Common.Builder
+namespace Umbraco.Core.DependencyInjection
{
public class UmbracoBuilder : IUmbracoBuilder
{
@@ -28,6 +31,8 @@ namespace Umbraco.Web.Common.Builder
Config = config;
BuilderLoggerFactory = loggerFactory;
TypeLoader = typeLoader;
+
+ AddCoreServices();
}
///
@@ -55,5 +60,12 @@ namespace Umbraco.Web.Common.Builder
_builders.Clear();
}
+
+ private void AddCoreServices()
+ {
+ // Register as singleton to allow injection everywhere.
+ Services.AddSingleton(p => p.GetService);
+ Services.AddSingleton();
+ }
}
}
diff --git a/src/Umbraco.Core/Events/EventAggregator.Notifications.cs b/src/Umbraco.Core/Events/EventAggregator.Notifications.cs
new file mode 100644
index 0000000000..00982b52d7
--- /dev/null
+++ b/src/Umbraco.Core/Events/EventAggregator.Notifications.cs
@@ -0,0 +1,70 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Umbraco.Core.Events
+{
+ ///
+ /// Contains types and methods that allow publishing general notifications.
+ ///
+ public partial class EventAggregator : IEventAggregator
+ {
+ private static readonly ConcurrentDictionary s_notificationHandlers
+ = new ConcurrentDictionary();
+
+ private Task PublishNotificationAsync(INotification notification, CancellationToken cancellationToken = default)
+ {
+ Type notificationType = notification.GetType();
+ NotificationHandlerWrapper handler = s_notificationHandlers.GetOrAdd(
+ notificationType,
+ t => (NotificationHandlerWrapper)Activator.CreateInstance(typeof(NotificationHandlerWrapperImpl<>).MakeGenericType(notificationType)));
+
+ return handler.HandleAsync(notification, cancellationToken, _serviceFactory, PublishCoreAsync);
+ }
+
+ private async Task PublishCoreAsync(
+ IEnumerable> allHandlers,
+ INotification notification,
+ CancellationToken cancellationToken)
+ {
+ foreach (Func handler in allHandlers)
+ {
+ await handler(notification, cancellationToken).ConfigureAwait(false);
+ }
+ }
+ }
+
+ internal abstract class NotificationHandlerWrapper
+ {
+ public abstract Task HandleAsync(
+ INotification notification,
+ CancellationToken cancellationToken,
+ ServiceFactory serviceFactory,
+ Func>, INotification, CancellationToken, Task> publish);
+ }
+
+ internal class NotificationHandlerWrapperImpl : NotificationHandlerWrapper
+ where TNotification : INotification
+ {
+ public override Task HandleAsync(
+ INotification notification,
+ CancellationToken cancellationToken,
+ ServiceFactory serviceFactory,
+ Func>, INotification, CancellationToken, Task> publish)
+ {
+ IEnumerable> handlers = serviceFactory
+ .GetInstances>()
+ .Select(x => new Func(
+ (theNotification, theToken) =>
+ x.HandleAsync((TNotification)theNotification, theToken)));
+
+ return publish(handlers, notification, cancellationToken);
+ }
+ }
+}
diff --git a/src/Umbraco.Core/Events/EventAggregator.cs b/src/Umbraco.Core/Events/EventAggregator.cs
new file mode 100644
index 0000000000..8d58175da4
--- /dev/null
+++ b/src/Umbraco.Core/Events/EventAggregator.cs
@@ -0,0 +1,68 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Umbraco.Core.Events
+{
+ ///
+ /// A factory method used to resolve all services.
+ /// For multiple instances, it will resolve against .
+ ///
+ /// Type of service to resolve.
+ /// An instance of type .
+ public delegate object ServiceFactory(Type serviceType);
+
+ ///
+ public partial class EventAggregator : IEventAggregator
+ {
+ private readonly ServiceFactory _serviceFactory;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The service instance factory.
+ public EventAggregator(ServiceFactory serviceFactory)
+ => _serviceFactory = serviceFactory;
+
+ ///
+ public Task PublishAsync(TNotification notification, CancellationToken cancellationToken = default)
+ where TNotification : INotification
+ {
+ // TODO: Introduce codegen efficient Guard classes to reduce noise.
+ if (notification == null)
+ {
+ throw new ArgumentNullException(nameof(notification));
+ }
+
+ return PublishNotificationAsync(notification, cancellationToken);
+ }
+ }
+
+ ///
+ /// Extensions for .
+ ///
+ public static class ServiceFactoryExtensions
+ {
+ ///
+ /// Gets an instance of .
+ ///
+ /// The type to return.
+ /// The service factory.
+ /// The new instance.
+ public static T GetInstance(this ServiceFactory factory)
+ => (T)factory(typeof(T));
+
+ ///
+ /// Gets a collection of instances of .
+ ///
+ /// The collection item type to return.
+ /// The service factory.
+ /// The new instance collection.
+ public static IEnumerable GetInstances(this ServiceFactory factory)
+ => (IEnumerable)factory(typeof(IEnumerable));
+ }
+}
diff --git a/src/Umbraco.Core/Events/IEventAggregator.cs b/src/Umbraco.Core/Events/IEventAggregator.cs
new file mode 100644
index 0000000000..bd01ad0b57
--- /dev/null
+++ b/src/Umbraco.Core/Events/IEventAggregator.cs
@@ -0,0 +1,48 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Umbraco.Core.Events
+{
+ ///
+ /// Defines an object that channels events from multiple objects into a single object
+ /// to simplify registration for clients.
+ ///
+ public interface IEventAggregator
+ {
+ ///
+ /// Asynchronously send a notification to multiple handlers
+ ///
+ /// The type of notification being handled.
+ /// The notification object.
+ /// An optional cancellation token.
+ /// A task that represents the publish operation.
+ Task PublishAsync(TNotification notification, CancellationToken cancellationToken = default)
+ where TNotification : INotification;
+ }
+
+ ///
+ /// A marker interface to represent a notification.
+ ///
+ public interface INotification
+ {
+ }
+
+ ///
+ /// Defines a handler for a notification.
+ ///
+ /// The type of notification being handled.
+ public interface INotificationHandler
+ where TNotification : INotification
+ {
+ ///
+ /// Handles a notification
+ ///
+ /// The notification
+ /// The cancellation token.
+ /// A representing the asynchronous operation.
+ Task HandleAsync(TNotification notification, CancellationToken cancellationToken);
+ }
+}
diff --git a/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs b/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs
index a9bf887c16..e2f2460d58 100644
--- a/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs
+++ b/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs
@@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Examine
diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs
index bb9140634c..7279eaf10c 100644
--- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs
+++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Cache
diff --git a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
index 6f0a52d033..8d2a2e19cc 100644
--- a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
+++ b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs
@@ -1,7 +1,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Services.Changes;
using Umbraco.Core.Sync;
diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs
index e68d6dabf8..0fee815560 100644
--- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs
+++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Compose
diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs
index 90701a888e..c700938534 100644
--- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs
+++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs
@@ -1,5 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Mapping;
using Umbraco.Core.Security;
using Umbraco.Web.Models.Mapping;
diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs
index 1f539782c7..f098cfaf57 100644
--- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs
+++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs
@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs
index e4272a44f3..31b3133e4d 100644
--- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs
+++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Web.Install;
using Umbraco.Web.Install.InstallSteps;
diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs
index ba4195faf0..05b7371d15 100644
--- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs
+++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs
@@ -1,4 +1,4 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs
index f657236cad..696f846d13 100644
--- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs
+++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs
@@ -4,7 +4,7 @@ using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
diff --git a/src/Umbraco.Infrastructure/CompositionExtensions.cs b/src/Umbraco.Infrastructure/CompositionExtensions.cs
index d7a1c1125b..703c35e06b 100644
--- a/src/Umbraco.Infrastructure/CompositionExtensions.cs
+++ b/src/Umbraco.Infrastructure/CompositionExtensions.cs
@@ -1,6 +1,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Dictionary;
diff --git a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs b/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs
index c7f222f0ca..fc26f922eb 100644
--- a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs
+++ b/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging.Serilog.Enrichers;
using Umbraco.Infrastructure.Logging.Serilog.Enrichers;
diff --git a/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs b/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs
index 856b6e892d..aa57383541 100644
--- a/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs
+++ b/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs
@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Logging.Viewer
diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs
index 08c890e5b0..2cca4a839f 100644
--- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs
+++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs
@@ -1,4 +1,4 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0.DataTypes
diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs
index df48ac8df0..910a9a25e2 100644
--- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs
+++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs
@@ -59,7 +59,7 @@ using Umbraco.Web.Trees;
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
using TextStringValueConverter = Umbraco.Core.PropertyEditors.ValueConverters.TextStringValueConverter;
using Microsoft.Extensions.Logging;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Core.HealthCheck;
using Umbraco.Core.HealthCheck.Checks;
diff --git a/src/Umbraco.Infrastructure/Search/ExamineComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineComposer.cs
index 87deb21bde..683ed48ecd 100644
--- a/src/Umbraco.Infrastructure/Search/ExamineComposer.cs
+++ b/src/Umbraco.Infrastructure/Search/ExamineComposer.cs
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
diff --git a/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs b/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs
index 6a048daca4..af59c27ef2 100644
--- a/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs
+++ b/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Web.WebAssets
diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs
index 324b5f0df7..81869a9261 100644
--- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs
+++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs
@@ -7,7 +7,7 @@ using Umbraco.Core.Models.PublishedContent;
using Umbraco.ModelsBuilder.Embedded.Building;
using Umbraco.Core.Configuration.Models;
using Microsoft.Extensions.Options;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.ModelsBuilder.Embedded.Compose
{
diff --git a/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs b/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs
index eb1b4b3d5f..17e707effd 100644
--- a/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs
+++ b/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Scoping;
diff --git a/src/Umbraco.TestData/LoadTestController.cs b/src/Umbraco.TestData/LoadTestController.cs
index ed9e0b456e..1d03c8bb2a 100644
--- a/src/Umbraco.TestData/LoadTestController.cs
+++ b/src/Umbraco.TestData/LoadTestController.cs
@@ -11,8 +11,8 @@ using System.Diagnostics;
using Umbraco.Core.Composing;
using System.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Core.Builder;
using Umbraco.Core.Strings;
+using Umbraco.Core.DependencyInjection;
// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting
diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs
index 89006ef245..77ee27b8c4 100644
--- a/src/Umbraco.Tests.Integration/RuntimeTests.cs
+++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs
@@ -1,29 +1,17 @@
-using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Options;
-using Moq;
-using NUnit.Framework;
using Microsoft.Extensions.Logging;
+using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Builder;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
-using Umbraco.Core.Configuration.Models;
-using Umbraco.Core.Logging;
-using Umbraco.Core.Persistence;
-using Umbraco.Core.Persistence.Mappers;
-using Umbraco.Core.Runtime;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Extensions;
-using Umbraco.Tests.Common;
using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
-using Umbraco.Tests.Integration.Testing;
-using Umbraco.Web.Common.Builder;
namespace Umbraco.Tests.Integration
{
@@ -70,8 +58,8 @@ namespace Umbraco.Tests.Integration
AppCaches.NoCache,
hostContext.Configuration,
testHelper.Profiler);
-
- var builder = new UmbracoBuilder(services, hostContext.Configuration, typeLoader, testHelper.ConsoleLoggerFactory);
+
+ var builder = new UmbracoBuilder(services, hostContext.Configuration, typeLoader, testHelper.ConsoleLoggerFactory);
builder.Services.AddUnique(AppCaches.NoCache);
builder.AddConfiguration();
builder.AddUmbracoCore();
@@ -109,7 +97,7 @@ namespace Umbraco.Tests.Integration
var webHostEnvironment = testHelper.GetWebHostEnvironment();
services.AddSingleton(testHelper.DbProviderFactoryCreator);
services.AddRequiredNetCoreServices(testHelper, webHostEnvironment);
-
+
// Add it!
var typeLoader = services.AddTypeLoader(
diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs
index 897bc38c2f..0fcf47978a 100644
--- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs
@@ -1,11 +1,9 @@
-using Moq;
+using Moq;
using Umbraco.Core;
-using Umbraco.Core.Builder;
using Umbraco.Core.Cache;
-using Umbraco.Core.Logging;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Runtime;
using Umbraco.Tests.Integration.Implementations;
-using Umbraco.Web.Common.Builder;
namespace Umbraco.Tests.Integration.TestServerTest
{
diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
index 5867e6522c..d60f49971a 100644
--- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
+++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
@@ -18,7 +18,7 @@ using Umbraco.Extensions;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;
using Umbraco.Web;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Web.Common.Controllers;
using Microsoft.Extensions.Hosting;
using Umbraco.Core.Cache;
diff --git a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs
index c556d4d29d..dacfd950e0 100644
--- a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs
+++ b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs
@@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs
index b61e61f20c..a8875de286 100644
--- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs
+++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs
@@ -1,41 +1,35 @@
-using System;
-using System.Threading.Tasks;
+using System;
+using System.Collections.Generic;
+using System.Data.Common;
+using System.Data.SqlClient;
+using System.IO;
using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
+using Microsoft.Extensions.Options;
+using Moq;
using NUnit.Framework;
+using Serilog;
+using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
-using Umbraco.Core.Configuration;
+using Umbraco.Core.Configuration.Models;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.IO;
-using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
+using Umbraco.Core.Runtime;
using Umbraco.Core.Scoping;
using Umbraco.Core.Strings;
+using Umbraco.Extensions;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
-using Umbraco.Extensions;
using Umbraco.Tests.Testing;
using Umbraco.Web;
-using Umbraco.Core.Runtime;
-using Umbraco.Core;
-using Moq;
-using System.Collections.Generic;
-using Microsoft.Extensions.Configuration;
-using System.Data.SqlClient;
-using System.Data.Common;
-using System.Diagnostics;
-using System.IO;
-using Umbraco.Core.Configuration.Models;
-using Microsoft.Extensions.Options;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Logging.Abstractions;
-using Serilog;
-using Umbraco.Core.Builder;
-using Umbraco.Web.Common.Builder;
-using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings;
namespace Umbraco.Tests.Integration.Testing
{
@@ -65,7 +59,8 @@ namespace Umbraco.Tests.Integration.Testing
[OneTimeTearDown]
public void FixtureTearDown()
{
- foreach (var a in _fixtureTeardown) a();
+ foreach (var a in _fixtureTeardown)
+ a();
}
[TearDown]
@@ -73,7 +68,8 @@ namespace Umbraco.Tests.Integration.Testing
{
if (_testTeardown != null)
{
- foreach (var a in _testTeardown) a();
+ foreach (var a in _testTeardown)
+ a();
}
_testTeardown = null;
FirstTestInFixture = false;
@@ -161,7 +157,7 @@ namespace Umbraco.Tests.Integration.Testing
});
return hostBuilder;
}
-
+
#endregion
#region IStartup
@@ -275,7 +271,8 @@ namespace Umbraco.Tests.Integration.Testing
{
lock (_dbLocker)
{
- if (_dbInstance != null) return _dbInstance;
+ if (_dbInstance != null)
+ return _dbInstance;
var localDb = new LocalDb();
if (localDb.IsAvailable == false)
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
index 4093dfb892..52bc1880a3 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
@@ -12,7 +12,7 @@ using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Tests.UnitTests.TestHelpers;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.TestHelpers
{
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
index 7bbfed4e85..5481bfcd76 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
@@ -1,6 +1,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Tests.UnitTests.TestHelpers
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs
index 4a6c73c8c4..44aacab944 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs
@@ -1,19 +1,19 @@
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
+using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Builder;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.Models;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
@@ -21,7 +21,6 @@ using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Scoping;
using Umbraco.Tests.TestHelpers;
-using Umbraco.Web.Common.Builder;
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components
{
@@ -49,12 +48,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components
var mediaFileSystem = Mock.Of();
var p = new ScopeProvider(f, fs, Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, typeFinder, NoAppCache.Instance);
- mock.Setup(x => x.GetService(typeof (ILogger))).Returns(logger);
+ mock.Setup(x => x.GetService(typeof(ILogger))).Returns(logger);
mock.Setup(x => x.GetService(typeof(ILogger))).Returns(loggerFactory.CreateLogger);
mock.Setup(x => x.GetService(typeof(ILoggerFactory))).Returns(loggerFactory);
- mock.Setup(x => x.GetService(typeof (IProfilingLogger))).Returns(new ProfilingLogger(loggerFactory.CreateLogger(), Mock.Of()));
- mock.Setup(x => x.GetService(typeof (IUmbracoDatabaseFactory))).Returns(f);
- mock.Setup(x => x.GetService(typeof (IScopeProvider))).Returns(p);
+ mock.Setup(x => x.GetService(typeof(IProfilingLogger))).Returns(new ProfilingLogger(loggerFactory.CreateLogger(), Mock.Of()));
+ mock.Setup(x => x.GetService(typeof(IUmbracoDatabaseFactory))).Returns(f);
+ mock.Setup(x => x.GetService(typeof(IScopeProvider))).Returns(p);
setup?.Invoke(mock);
return mock.Object;
@@ -62,7 +61,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components
private static IServiceCollection MockRegister()
{
- return Mock.Of();
+ // Why mock something you can spin up an instance of?
+ return new ServiceCollection(); // Mock.Of();
}
private static TypeLoader MockTypeLoader()
@@ -93,11 +93,16 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components
m.Setup(x => x.GetService(It.Is(t => t == typeof(ISomeResource)))).Returns(() => new SomeResource());
m.Setup(x => x.GetService(It.IsAny())).Returns((type) =>
{
- if (type == typeof(Composer1)) return new Composer1();
- if (type == typeof(Composer5)) return new Composer5();
- if (type == typeof(Component5)) return new Component5(new SomeResource());
- if (type == typeof(IProfilingLogger)) return new ProfilingLogger(Mock.Of>(), Mock.Of());
- if (type == typeof(ILogger)) return Mock.Of>();
+ if (type == typeof(Composer1))
+ return new Composer1();
+ if (type == typeof(Composer5))
+ return new Composer5();
+ if (type == typeof(Component5))
+ return new Component5(new SomeResource());
+ if (type == typeof(IProfilingLogger))
+ return new ProfilingLogger(Mock.Of>(), Mock.Of());
+ if (type == typeof(ILogger))
+ return Mock.Of>();
throw new NotSupportedException(type.FullName);
});
});
@@ -212,16 +217,23 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components
var typeLoader = MockTypeLoader();
var factory = MockFactory(m =>
{
- m.Setup(x => x.GetService(It.Is(t => t == typeof (ISomeResource)))).Returns(() => new SomeResource());
+ m.Setup(x => x.GetService(It.Is(t => t == typeof(ISomeResource)))).Returns(() => new SomeResource());
m.Setup(x => x.GetService(It.IsAny())).Returns((type) =>
{
- if (type == typeof(Composer1)) return new Composer1();
- if (type == typeof(Composer5)) return new Composer5();
- if (type == typeof(Composer5a)) return new Composer5a();
- if (type == typeof(Component5)) return new Component5(new SomeResource());
- if (type == typeof(Component5a)) return new Component5a();
- if (type == typeof(IProfilingLogger)) return new ProfilingLogger(Mock.Of>(), Mock.Of());
- if (type == typeof(ILogger)) return Mock.Of>();
+ if (type == typeof(Composer1))
+ return new Composer1();
+ if (type == typeof(Composer5))
+ return new Composer5();
+ if (type == typeof(Composer5a))
+ return new Composer5a();
+ if (type == typeof(Component5))
+ return new Component5(new SomeResource());
+ if (type == typeof(Component5a))
+ return new Component5a();
+ if (type == typeof(IProfilingLogger))
+ return new ProfilingLogger(Mock.Of>(), Mock.Of());
+ if (type == typeof(ILogger))
+ return Mock.Of>();
throw new NotSupportedException(type.FullName);
});
});
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs
index 6bc33605ac..b4131ca790 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs
@@ -1,18 +1,14 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Builder;
-using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
-using Umbraco.Core.Logging;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.UnitTests.TestHelpers;
-using Umbraco.Web.Common.Builder;
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing
{
@@ -128,7 +124,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing
//builder.Append(); // does not compile
Assert.Throws(() =>
- builder.Append(new[] { typeof (Resolved4) }) // throws
+ builder.Append(new[] { typeof(Resolved4) }) // throws
);
}
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs
index c756023151..c87b267c1a 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs
@@ -11,7 +11,7 @@ using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.UnitTests.TestHelpers;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing
{
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs
index 6ebd0c677a..17e406e02f 100644
--- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs
@@ -13,7 +13,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.PackageActions;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.UnitTests.TestHelpers;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing
{
diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Events/EventAggregatorTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Events/EventAggregatorTests.cs
new file mode 100644
index 0000000000..08d78af59e
--- /dev/null
+++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Events/EventAggregatorTests.cs
@@ -0,0 +1,87 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Moq;
+using NUnit.Framework;
+using Umbraco.Core.DependencyInjection;
+using Umbraco.Core.Events;
+using Umbraco.Tests.TestHelpers;
+
+namespace Umbraco.Tests.UnitTests.Umbraco.Core.Events
+{
+ public class EventAggregatorTests
+ {
+ private const int A = 3;
+ private const int B = 5;
+ private const int C = 7;
+ private IUmbracoBuilder _builder;
+
+ [SetUp]
+ public void Setup()
+ {
+ IServiceCollection register = TestHelper.GetServiceCollection();
+ _builder = new UmbracoBuilder(register, Mock.Of(), TestHelper.GetMockedTypeLoader());
+ }
+
+ [Test]
+ public async Task CanPublishEvents()
+ {
+ _builder.Services.AddScoped();
+ _builder.AddNotificationHandler();
+ _builder.AddNotificationHandler();
+ _builder.AddNotificationHandler();
+ ServiceProvider provider = _builder.Services.BuildServiceProvider();
+
+ var notification = new Notification();
+ IEventAggregator aggregator = provider.GetService();
+ await aggregator.PublishAsync(notification);
+
+ Assert.AreEqual(A + B + C, notification.SubscriberCount);
+ }
+
+ public class Notification : INotification
+ {
+ public int SubscriberCount { get; set; }
+ }
+
+ public class NotificationHandlerA : INotificationHandler
+ {
+ public Task HandleAsync(Notification notification, CancellationToken cancellationToken)
+ {
+ notification.SubscriberCount += A;
+ return Task.CompletedTask;
+ }
+ }
+
+ public class NotificationHandlerB : INotificationHandler
+ {
+ public Task HandleAsync(Notification notification, CancellationToken cancellationToken)
+ {
+ notification.SubscriberCount += B;
+ return Task.CompletedTask;
+ }
+ }
+
+ public class NotificationHandlerC : INotificationHandler
+ {
+ private readonly Adder _adder;
+
+ public NotificationHandlerC(Adder adder) => _adder = adder;
+
+ public Task HandleAsync(Notification notification, CancellationToken cancellationToken)
+ {
+ notification.SubscriberCount = _adder.Add(notification.SubscriberCount, C);
+ return Task.CompletedTask;
+ }
+ }
+
+ public class Adder
+ {
+ public int Add(int a, int b) => a + b;
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs
index 8d2a6eb217..1800abc8a8 100644
--- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs
+++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs
@@ -1,16 +1,13 @@
-using System;
+using Moq;
+using NUnit.Framework;
+using System;
using System.Linq;
using System.Threading;
-using Moq;
-using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Builder;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Composing;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
-using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Tests.Common;
using Umbraco.Tests.TestHelpers;
@@ -19,7 +16,6 @@ using Umbraco.Web;
using Umbraco.Web.Cache;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
-using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Tests.Cache
{
diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs
index d3c9eaf36d..840ec58f13 100644
--- a/src/Umbraco.Tests/Published/ConvertersTests.cs
+++ b/src/Umbraco.Tests/Published/ConvertersTests.cs
@@ -3,15 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Composing;
-using Umbraco.Core.IO;
-using Umbraco.Core.Logging;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
@@ -21,7 +17,6 @@ using Umbraco.Core.Strings;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
-using Umbraco.Web.Common.Builder;
using Umbraco.Web.PublishedCache;
namespace Umbraco.Tests.Published
diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs
index 5ab6aeaa1d..4e1540a525 100644
--- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs
+++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs
@@ -6,12 +6,9 @@ using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Events;
using Umbraco.Core.IO;
-using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Scoping;
@@ -21,7 +18,7 @@ using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Web;
using Current = Umbraco.Web.Composing.Current;
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.Scoping
{
diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs
index a048c76022..6e27bdd07c 100644
--- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs
+++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs
@@ -15,8 +15,8 @@ using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence;
using Umbraco.Persistance.SqlCe;
using Umbraco.Web;
-using Umbraco.Web.Common.Builder;
using Current = Umbraco.Web.Composing.Current;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.TestHelpers
{
diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs
index b780665c23..533966f5a9 100644
--- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs
+++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs
@@ -1,14 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Web.Http.Validation;
-using System.Web.Routing;
-using System.Web.Security;
-using System.Xml.Linq;
-using Examine;
+using Examine;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -16,20 +6,28 @@ using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using NUnit.Framework;
using Serilog;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Web.Routing;
+using System.Web.Security;
+using System.Xml.Linq;
using Umbraco.Core;
-using Umbraco.Core.Builder;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.CompositionExtensions;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Events;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.IO.MediaPathSchemes;
using Umbraco.Core.Logging;
-using Umbraco.Core.Logging.Serilog;
using Umbraco.Core.Manifest;
using Umbraco.Core.Mapping;
using Umbraco.Core.Media;
@@ -52,7 +50,6 @@ using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.Actions;
using Umbraco.Web.AspNet;
-using Umbraco.Web.Common.Builder;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Hosting;
using Umbraco.Web.Install;
@@ -136,7 +133,7 @@ namespace Umbraco.Tests.Testing
protected IPasswordHasher PasswordHasher => Factory.GetRequiredService();
protected Lazy PropertyEditorCollection => new Lazy(() => Factory.GetRequiredService());
protected ILocalizationService LocalizationService => Factory.GetRequiredService();
- protected ILocalizedTextService LocalizedTextService { get; private set; }
+ protected ILocalizedTextService LocalizedTextService { get; private set; }
protected IShortStringHelper ShortStringHelper => Factory?.GetRequiredService() ?? TestHelper.ShortStringHelper;
protected IImageUrlGenerator ImageUrlGenerator => Factory.GetRequiredService();
protected UploadAutoFillProperties UploadAutoFillProperties => Factory.GetRequiredService();
@@ -389,30 +386,30 @@ namespace Umbraco.Tests.Testing
.ComposeCoreMappingProfiles();
}
- protected virtual TypeLoader GetTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IHostingEnvironment hostingEnvironment, ILogger logger, IProfilingLogger profilingLogger , UmbracoTestOptions.TypeLoader option)
+ protected virtual TypeLoader GetTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IHostingEnvironment hostingEnvironment, ILogger logger, IProfilingLogger profilingLogger, UmbracoTestOptions.TypeLoader option)
{
switch (option)
{
case UmbracoTestOptions.TypeLoader.Default:
- return _commonTypeLoader ?? (_commonTypeLoader = CreateCommonTypeLoader(typeFinder, runtimeCache, logger, profilingLogger , hostingEnvironment));
+ return _commonTypeLoader ?? (_commonTypeLoader = CreateCommonTypeLoader(typeFinder, runtimeCache, logger, profilingLogger, hostingEnvironment));
case UmbracoTestOptions.TypeLoader.PerFixture:
- return _featureTypeLoader ?? (_featureTypeLoader = CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, profilingLogger , hostingEnvironment));
+ return _featureTypeLoader ?? (_featureTypeLoader = CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, profilingLogger, hostingEnvironment));
case UmbracoTestOptions.TypeLoader.PerTest:
- return CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, profilingLogger , hostingEnvironment);
+ return CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, profilingLogger, hostingEnvironment);
default:
throw new ArgumentOutOfRangeException(nameof(option));
}
}
- protected virtual TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger logger, IProfilingLogger profilingLogger , IHostingEnvironment hostingEnvironment)
+ protected virtual TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger logger, IProfilingLogger profilingLogger, IHostingEnvironment hostingEnvironment)
{
- return CreateCommonTypeLoader(typeFinder, runtimeCache, logger, profilingLogger , hostingEnvironment);
+ return CreateCommonTypeLoader(typeFinder, runtimeCache, logger, profilingLogger, hostingEnvironment);
}
// common to all tests = cannot be overriden
- private static TypeLoader CreateCommonTypeLoader(ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger logger, IProfilingLogger profilingLogger , IHostingEnvironment hostingEnvironment)
+ private static TypeLoader CreateCommonTypeLoader(ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger logger, IProfilingLogger profilingLogger, IHostingEnvironment hostingEnvironment)
{
- return new TypeLoader(typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, profilingLogger , false, new[]
+ return new TypeLoader(typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, profilingLogger, false, new[]
{
Assembly.Load("Umbraco.Core"),
Assembly.Load("Umbraco.Web"),
@@ -498,7 +495,7 @@ namespace Umbraco.Tests.Testing
Builder.Services.AddUnique(factory
=> TestObjects.GetScopeProvider(_loggerFactory, factory.GetService(), factory.GetService(), factory.GetService()));
- Builder.Services.AddUnique(factory => (IScopeAccessor) factory.GetRequiredService());
+ Builder.Services.AddUnique(factory => (IScopeAccessor)factory.GetRequiredService());
Builder.ComposeServices();
diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
index 10eefcc47a..a6f6bc8fb8 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
@@ -149,7 +149,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
[FilterAllowedOutgoingContent(typeof(IEnumerable))]
- public IEnumerable GetByIds([FromQuery]int[] ids)
+ public IEnumerable GetByIds([FromQuery] int[] ids)
{
var foundContent = _contentService.GetByIds(ids);
return foundContent.Select(MapToDisplay);
@@ -164,7 +164,8 @@ namespace Umbraco.Web.BackOffice.Controllers
/// Permission check is done for letter 'R' which is for which the user must have access to update
///
public async Task>> PostSaveUserGroupPermissions(UserGroupPermissionsSave saveModel)
- { if (saveModel.ContentId <= 0) return NotFound();
+ {
+ if (saveModel.ContentId <= 0) return NotFound();
// TODO: Should non-admins be allowed to set granular permissions?
@@ -347,7 +348,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.ContentPermissionBrowseById)]
[DetermineAmbiguousActionByPassingParameters]
public ContentItemDisplay GetById(int id)
@@ -367,7 +368,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.ContentPermissionBrowseById)]
[DetermineAmbiguousActionByPassingParameters]
public ContentItemDisplay GetById(Guid id)
@@ -388,7 +389,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.ContentPermissionBrowseById)]
[DetermineAmbiguousActionByPassingParameters]
public ContentItemDisplay GetById(Udi id)
@@ -407,7 +408,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[DetermineAmbiguousActionByPassingParameters]
public ContentItemDisplay GetEmpty(string contentTypeAlias, int parentId)
{
@@ -426,7 +427,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public ContentItemDisplay GetEmptyByKey(Guid contentTypeKey, int parentId)
{
var contentType = _contentTypeService.Get(contentTypeKey);
@@ -454,7 +455,7 @@ namespace Umbraco.Web.BackOffice.Controllers
return mapped;
}
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[DetermineAmbiguousActionByPassingParameters]
public ContentItemDisplay GetEmpty(int blueprintId, int parentId)
{
@@ -598,7 +599,7 @@ namespace Umbraco.Web.BackOffice.Controllers
/// The name of the blueprint
///
[HttpPost]
- public ActionResult CreateBlueprintFromContent([FromQuery]int contentId, [FromQuery]string name)
+ public ActionResult CreateBlueprintFromContent([FromQuery] int contentId, [FromQuery] string name)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));
@@ -632,32 +633,32 @@ namespace Umbraco.Web.BackOffice.Controllers
}
}
- ///
- /// Saves content
- ///
- ///
- [FileUploadCleanupFilter]
- [ContentSaveValidation]
- public async Task PostSaveBlueprint([ModelBinder(typeof(BlueprintItemBinder))] ContentItemSave contentItem)
- {
- var contentItemDisplay = await PostSaveInternal(contentItem,
- content =>
- {
- EnsureUniqueName(content.Name, content, "Name");
+ ///
+ /// Saves content
+ ///
+ ///
+ [FileUploadCleanupFilter]
+ [ContentSaveValidation]
+ public async Task PostSaveBlueprint([ModelBinder(typeof(BlueprintItemBinder))] ContentItemSave contentItem)
+ {
+ var contentItemDisplay = await PostSaveInternal(contentItem,
+ content =>
+ {
+ EnsureUniqueName(content.Name, content, "Name");
- _contentService.SaveBlueprint(contentItem.PersistedContent, _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.Id);
+ _contentService.SaveBlueprint(contentItem.PersistedContent, _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.Id);
//we need to reuse the underlying logic so return the result that it wants
return OperationResult.Succeed(new EventMessages());
- },
- content =>
- {
- var display = MapToDisplay(content);
- SetupBlueprint(display, content);
- return display;
- });
+ },
+ content =>
+ {
+ var display = MapToDisplay(content);
+ SetupBlueprint(display, content);
+ return display;
+ });
- return contentItemDisplay;
- }
+ return contentItemDisplay;
+ }
///
/// Saves content
@@ -665,7 +666,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
[FileUploadCleanupFilter]
[ContentSaveValidation]
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public async Task PostSave([ModelBinder(typeof(ContentItemBinder))] ContentItemSave contentItem)
{
var contentItemDisplay = await PostSaveInternal(
@@ -1459,7 +1460,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
private string GetVariantName(string culture, string segment)
{
- if(culture.IsNullOrWhiteSpace() && segment.IsNullOrWhiteSpace())
+ if (culture.IsNullOrWhiteSpace() && segment.IsNullOrWhiteSpace())
{
// TODO: Get name for default variant from somewhere?
return "Default";
@@ -1677,7 +1678,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
/// The content and variants to unpublish
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public async Task> PostUnpublish(UnpublishContent model)
{
var foundContent = _contentService.GetById(model.Id);
@@ -1685,7 +1686,7 @@ namespace Umbraco.Web.BackOffice.Controllers
if (foundContent == null)
{
HandleContentNotFound(model.Id);
- }
+ }
// Authorize...
var resource = new ContentPermissionsResource(foundContent, ActionUnpublish.ActionLetter);
@@ -2309,7 +2310,7 @@ namespace Umbraco.Web.BackOffice.Controllers
return notifications;
}
- public IActionResult PostNotificationOptions(int contentId, [FromQuery(Name="notifyOptions[]")] string[] notifyOptions)
+ public IActionResult PostNotificationOptions(int contentId, [FromQuery(Name = "notifyOptions[]")] string[] notifyOptions)
{
if (contentId <= 0) return NotFound();
var content = _contentService.GetById(contentId);
@@ -2459,7 +2460,7 @@ namespace Umbraco.Web.BackOffice.Controllers
// set up public access using role based access
[Authorize(Policy = AuthorizationPolicies.ContentPermissionProtectById)]
[HttpPost]
- public IActionResult PostPublicAccess(int contentId, [FromQuery(Name = "groups[]")]string[] groups, [FromQuery(Name = "usernames[]")]string[] usernames, int loginPageId, int errorPageId)
+ public IActionResult PostPublicAccess(int contentId, [FromQuery(Name = "groups[]")] string[] groups, [FromQuery(Name = "usernames[]")] string[] usernames, int loginPageId, int errorPageId)
{
if ((groups == null || groups.Any() == false) && (usernames == null || usernames.Any() == false))
{
@@ -2520,7 +2521,7 @@ namespace Umbraco.Web.BackOffice.Controllers
}
return _publicAccessService.Save(entry).Success
- ? (IActionResult) Ok()
+ ? (IActionResult)Ok()
: Problem();
}
@@ -2541,7 +2542,7 @@ namespace Umbraco.Web.BackOffice.Controllers
}
return _publicAccessService.Delete(entry).Success
- ? (IActionResult) Ok()
+ ? (IActionResult)Ok()
: Problem();
}
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs b/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs
index d96708b11d..a69cc6739b 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/DashboardController.cs
@@ -210,7 +210,7 @@ namespace Umbraco.Web.BackOffice.Controllers
// return IDashboardSlim - we don't need sections nor access rules
[ValidateAngularAntiForgeryToken]
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public IEnumerable> GetDashboard(string section)
{
var currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
index 409967fb67..49a20f1150 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
@@ -122,7 +122,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public MediaItemDisplay GetEmpty(string contentTypeAlias, int parentId)
{
var contentType = _mediaTypeService.Get(contentTypeAlias);
@@ -170,7 +170,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.MediaPermissionPathById)]
[DetermineAmbiguousActionByPassingParameters]
public MediaItemDisplay GetById(int id)
@@ -191,7 +191,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.MediaPermissionPathById)]
[DetermineAmbiguousActionByPassingParameters]
public MediaItemDisplay GetById(Guid id)
@@ -212,7 +212,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.MediaPermissionPathById)]
[DetermineAmbiguousActionByPassingParameters]
public MediaItemDisplay GetById(Udi id)
@@ -513,7 +513,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
[FileUploadCleanupFilter]
[MediaItemSaveValidation]
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public MediaItemDisplay PostSave(
[ModelBinder(typeof(MediaItemBinder))]
MediaItemSave contentItem)
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs
index a97ed9c2ad..267539c97f 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs
@@ -151,7 +151,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public MemberDisplay GetByKey(Guid key)
{
var foundMember = _memberService.GetByKey(key);
@@ -167,7 +167,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public MemberDisplay GetEmpty(string contentTypeAlias = null)
{
IMember emptyContent;
@@ -194,7 +194,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
[FileUploadCleanupFilter]
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[MemberSaveValidation]
public async Task> PostSave(
[ModelBinder(typeof(MemberBinder))]
diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
index 5052f5146e..9d7999b9f7 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
@@ -222,7 +222,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.AdminUserEditsRequireAdmin)]
public UserDisplay GetById(int id)
{
@@ -240,7 +240,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
[Authorize(Policy = AuthorizationPolicies.AdminUserEditsRequireAdmin)]
public IEnumerable GetByIds([FromJsonPath]int[] ids)
{
@@ -575,7 +575,7 @@ namespace Umbraco.Web.BackOffice.Controllers
///
///
///
- [TypeFilter(typeof(OutgoingEditorModelEventAttribute))]
+ [OutgoingEditorModelEvent]
public UserDisplay PostSaveUser(UserSave userSave)
{
if (userSave == null) throw new ArgumentNullException(nameof(userSave));
diff --git a/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs
index 4e8fe01b7f..2c14e33e2b 100644
--- a/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs
+++ b/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs
@@ -1,4 +1,4 @@
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Web.BackOffice.Trees;
diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs
index 35b7e8e859..79c7a9d29a 100644
--- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs
@@ -1,11 +1,9 @@
-using System;
+using System;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.VisualBasic;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Web.BackOffice.Security;
-using Umbraco.Web.Common.Builder;
namespace Umbraco.Extensions
{
@@ -36,7 +34,7 @@ namespace Umbraco.Extensions
builder.Services
.AddAuthentication() // This just creates a builder, nothing more
- // Add our custom schemes which are cookie handlers
+ // Add our custom schemes which are cookie handlers
.AddCookie(Core.Constants.Security.BackOfficeAuthenticationType)
.AddCookie(Core.Constants.Security.BackOfficeExternalAuthenticationType, o =>
{
diff --git a/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs b/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs
index 6df63a1655..eeb0903e88 100644
--- a/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs
+++ b/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs
@@ -1,5 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Mapping;
using Umbraco.Web.BackOffice.Mapping;
diff --git a/src/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventAttribute.cs
index d5df536dae..4687d108a0 100644
--- a/src/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventAttribute.cs
+++ b/src/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventAttribute.cs
@@ -4,47 +4,60 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Umbraco.Core;
using Umbraco.Core.Security;
using Umbraco.Web.Editors;
-using Umbraco.Web.Security;
namespace Umbraco.Web.BackOffice.Filters
{
///
/// Used to emit outgoing editor model events
///
- internal sealed class OutgoingEditorModelEventAttribute : ActionFilterAttribute
+ internal sealed class OutgoingEditorModelEventAttribute : TypeFilterAttribute
{
- private readonly IUmbracoContextAccessor _umbracoContextAccessor;
- private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
-
- public OutgoingEditorModelEventAttribute(IUmbracoContextAccessor umbracoContextAccessor, IBackOfficeSecurityAccessor backofficeSecurityAccessor)
+ public OutgoingEditorModelEventAttribute() : base(typeof(OutgoingEditorModelEventFilter))
{
- _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
- _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
}
- public override void OnActionExecuted(ActionExecutedContext context)
+
+ private class OutgoingEditorModelEventFilter : IActionFilter
{
- if (context.Result == null) return;
- var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
- var user = _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
- if (user == null) return;
+ private readonly IUmbracoContextAccessor _umbracoContextAccessor;
- if (context.Result is ObjectResult objectContent)
+ private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
+
+ public OutgoingEditorModelEventFilter(
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
{
- var model = objectContent.Value;
-
- if (model != null)
- {
- var args = new EditorModelEventArgs(
- model,
- umbracoContext);
- EditorModelEventManager.EmitEvent(context, args);
- objectContent.Value = args.Model;
- }
+ _umbracoContextAccessor = umbracoContextAccessor
+ ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
+ _backOfficeSecurityAccessor = backOfficeSecurityAccessor
+ ?? throw new ArgumentNullException(nameof(backOfficeSecurityAccessor));
}
- base.OnActionExecuted(context);
+ public void OnActionExecuted(ActionExecutedContext context)
+ {
+ if (context.Result == null) return;
+
+ var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
+ var user = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
+ if (user == null) return;
+
+ if (context.Result is ObjectResult objectContent)
+ {
+ var model = objectContent.Value;
+
+ if (model != null)
+ {
+ var args = new EditorModelEventArgs(model, umbracoContext);
+ EditorModelEventManager.EmitEvent(context, args);
+ objectContent.Value = args.Model;
+ }
+ }
+ }
+
+ public void OnActionExecuting(ActionExecutingContext context)
+ {
+ }
}
}
}
diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs
index 2f1b42aed5..44896016cd 100644
--- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs
+++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs
@@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
diff --git a/src/Umbraco.Web.BackOffice/Security/AuthenticationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Security/AuthenticationBuilderExtensions.cs
index e2a7aeccaf..9949018d43 100644
--- a/src/Umbraco.Web.BackOffice/Security/AuthenticationBuilderExtensions.cs
+++ b/src/Umbraco.Web.BackOffice/Security/AuthenticationBuilderExtensions.cs
@@ -1,5 +1,5 @@
-using System;
-using Umbraco.Core.Builder;
+using System;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Web.BackOffice.Security
{
diff --git a/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs b/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs
index e994571c90..9b06e07f7c 100644
--- a/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs
+++ b/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Web.BackOffice.SignalR
diff --git a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs
index 1fae03ba75..3bf4e9059b 100644
--- a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs
@@ -1,18 +1,17 @@
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Server.Kestrel.Core;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
using System;
-using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
+using Microsoft.AspNetCore.Server.Kestrel.Core;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -20,12 +19,12 @@ using Serilog;
using Smidge;
using Smidge.Nuglify;
using Umbraco.Core;
-using Umbraco.Core.Builder;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Configuration.Models.Validation;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
@@ -42,7 +41,7 @@ using Umbraco.Web.Common.ModelBinders;
using Umbraco.Web.Common.Profiler;
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
-namespace Umbraco.Web.Common.Builder
+namespace Umbraco.Core.DependencyInjection
{
// TODO: We could add parameters to configure each of these for flexibility
public static class UmbracoBuilderExtensions
@@ -52,8 +51,10 @@ namespace Umbraco.Web.Common.Builder
IWebHostEnvironment webHostEnvironment,
IConfiguration config)
{
- if (services is null) throw new ArgumentNullException(nameof(services));
- if (config is null) throw new ArgumentNullException(nameof(config));
+ if (services is null)
+ throw new ArgumentNullException(nameof(services));
+ if (config is null)
+ throw new ArgumentNullException(nameof(config));
var loggingConfig = new LoggingConfiguration(Path.Combine(webHostEnvironment.ContentRootPath, "umbraco", "logs"));
@@ -79,7 +80,8 @@ namespace Umbraco.Web.Common.Builder
/// Composes Composers
public static IUmbracoBuilder AddUmbracoCore(this IUmbracoBuilder builder)
{
- if (builder is null) throw new ArgumentNullException(nameof(builder));
+ if (builder is null)
+ throw new ArgumentNullException(nameof(builder));
builder.Services.AddLazySupport();
diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs
index c1f9849621..2b077fe840 100644
--- a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs
+++ b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs
@@ -14,7 +14,7 @@ using SixLabors.ImageSharp.Web.Processors;
using SixLabors.ImageSharp.Web.Providers;
using Smidge;
using Smidge.Nuglify;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Configuration.Models.Validation;
using Umbraco.Web.Common.ApplicationModels;
diff --git a/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs b/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs
index 702c30f692..3c00b0d3bc 100644
--- a/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs
+++ b/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Common.Profiler
diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs
index 58fa5ea317..a23f880e7e 100644
--- a/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs
+++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Web.Common.Middleware;
diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs
index f20ab5ab75..f6849215df 100644
--- a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs
+++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Diagnostics;
diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs
index 5b3d776679..1058192034 100644
--- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs
+++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs
@@ -1,7 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Smidge.FileProcessors;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Runtime;
using Umbraco.Core.WebAssets;
diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs
index ca62523c4d..d86e6a8776 100644
--- a/src/Umbraco.Web.UI.NetCore/Startup.cs
+++ b/src/Umbraco.Web.UI.NetCore/Startup.cs
@@ -5,7 +5,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Extensions;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
namespace Umbraco.Web.UI.NetCore
{
diff --git a/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs
index 3715f5e37b..72d12809e2 100644
--- a/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
-using Umbraco.Core.Builder;
-using Umbraco.Web.Common.Builder;
+using Umbraco.Core.DependencyInjection;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Web.Website.ViewEngines;
namespace Umbraco.Extensions
diff --git a/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs b/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs
index ce3ff7271e..a40b29aea2 100644
--- a/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs
+++ b/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Extensions;
using Umbraco.Web.Website.Routing;
diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs
index 80fa50f294..49cff7196e 100644
--- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs
+++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs
@@ -3,7 +3,7 @@ using System.Web.Security;
using Microsoft.AspNet.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Templates;
diff --git a/src/Umbraco.Web/UmbracoBuilderExtensions.cs b/src/Umbraco.Web/UmbracoBuilderExtensions.cs
index 422d0a8b23..bb6fe29c93 100644
--- a/src/Umbraco.Web/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Web/UmbracoBuilderExtensions.cs
@@ -1,7 +1,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Web.Routing;
namespace Umbraco.Web
diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs
index c591191524..75e0d6123f 100644
--- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs
+++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs
@@ -1,5 +1,5 @@
using Umbraco.Core;
-using Umbraco.Core.Builder;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.WebAssets;