diff --git a/src/Umbraco.Core/Events/INotificationAsyncHandler.cs b/src/Umbraco.Core/Events/INotificationAsyncHandler.cs
new file mode 100644
index 0000000000..cdcc21542f
--- /dev/null
+++ b/src/Umbraco.Core/Events/INotificationAsyncHandler.cs
@@ -0,0 +1,25 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System.Threading;
+using System.Threading.Tasks;
+using Umbraco.Cms.Core.Notifications;
+
+namespace Umbraco.Cms.Core.Events
+{
+ ///
+ /// Defines a handler for a async notification.
+ ///
+ /// The type of notification being handled.
+ public interface INotificationAsyncHandler
+ 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.Core/Events/INotificationHandler.cs b/src/Umbraco.Core/Events/INotificationHandler.cs
index d362477733..548bec39b8 100644
--- a/src/Umbraco.Core/Events/INotificationHandler.cs
+++ b/src/Umbraco.Core/Events/INotificationHandler.cs
@@ -1,8 +1,6 @@
-// Copyright (c) Umbraco.
+// Copyright (c) Umbraco.
// See LICENSE for more details.
-using System.Threading;
-using System.Threading.Tasks;
using Umbraco.Cms.Core.Notifications;
namespace Umbraco.Cms.Core.Events
@@ -20,20 +18,4 @@ namespace Umbraco.Cms.Core.Events
/// The notification
void Handle(TNotification notification);
}
-
- ///
- /// Defines a handler for a async notification.
- ///
- /// The type of notification being handled.
- public interface INotificationAsyncHandler
- 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.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs
index 61d96e2e61..c7f317a4ad 100644
--- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs
+++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs
@@ -67,15 +67,15 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
.AddMainDom()
.AddLogging();
- builder.Services.AddUnique();
- builder.Services.AddUnique(factory => factory.GetRequiredService().CreateDatabase());
- builder.Services.AddUnique(factory => factory.GetRequiredService().SqlContext);
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton(factory => factory.GetRequiredService().CreateDatabase());
+ builder.Services.AddSingleton(factory => factory.GetRequiredService().SqlContext);
builder.NPocoMappers().Add();
builder.PackageMigrationPlans().Add(() => builder.TypeLoader.GetPackageMigrationPlans());
- builder.Services.AddUnique();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
builder.AddNotificationAsyncHandler();
builder.AddNotificationAsyncHandler();
@@ -93,21 +93,21 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
builder.Mappers().AddCoreMappers();
// register the scope provider
- builder.Services.AddUnique(); // implements both IScopeProvider and IScopeAccessor
- builder.Services.AddUnique(f => f.GetRequiredService());
- builder.Services.AddUnique(f => f.GetRequiredService());
+ builder.Services.AddSingleton(); // implements both IScopeProvider and IScopeAccessor
+ builder.Services.AddSingleton(f => f.GetRequiredService());
+ builder.Services.AddSingleton(f => f.GetRequiredService());
builder.Services.AddScoped();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
// register database builder
// *not* a singleton, don't want to keep it around
builder.Services.AddTransient();
// register manifest parser, will be injected in collection builders where needed
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
// register the manifest filter collection builder (collection is empty by default)
builder.ManifestFilters();
@@ -116,28 +116,28 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
.Add()
.Add();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique(factory
+ builder.Services.AddSingleton(factory
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetRequiredService>().Value)));
- builder.Services.AddUnique();
- builder.Services.AddUnique(factory => new MigrationBuilder(factory));
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton(factory => new MigrationBuilder(factory));
builder.AddPreValueMigrators();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
// register the published snapshot accessor - the "current" published snapshot is in the umbraco context
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
// Config manipulator
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
// discovered when CoreBootManager configures the converters. We will remove the basic one defined
@@ -146,20 +146,26 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
.Remove();
// register *all* checks, except those marked [HideFromTypeFinder] of course
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.Services.AddScoped();
// replace
- builder.Services.AddUnique();
+ builder.Services.AddSingleton(
+ services => new EmailSender(
+ services.GetRequiredService>(),
+ services.GetRequiredService>(),
+ services.GetRequiredService(),
+ services.GetService>(),
+ services.GetService>()));
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.Services.AddScoped();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddScoped(factory =>
{
@@ -169,29 +175,29 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
});
// register accessors for cultures
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
// Add default ImageSharp configuration and service implementations
- builder.Services.AddUnique(SixLabors.ImageSharp.Configuration.Default);
- builder.Services.AddUnique();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton(SixLabors.ImageSharp.Configuration.Default);
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.AddInstaller();
// Services required to run background jobs (with out the handler)
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
return builder;
}
@@ -201,16 +207,16 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
///
private static IUmbracoBuilder AddLogging(this IUmbracoBuilder builder)
{
- builder.Services.AddUnique();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
return builder;
}
private static IUmbracoBuilder AddMainDom(this IUmbracoBuilder builder)
{
- builder.Services.AddUnique(factory =>
+ builder.Services.AddSingleton(factory =>
{
var globalSettings = factory.GetRequiredService>();
var connectionStrings = factory.GetRequiredService>();
@@ -259,9 +265,9 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
public static IUmbracoBuilder AddLogViewer(this IUmbracoBuilder builder)
{
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder.SetLogViewer();
- builder.Services.AddUnique(factory => new SerilogJsonLogViewer(factory.GetRequiredService>(),
+ builder.Services.AddSingleton(factory => new SerilogJsonLogViewer(factory.GetRequiredService>(),
factory.GetRequiredService(),
factory.GetRequiredService(),
Log.Logger));
@@ -273,7 +279,7 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
public static IUmbracoBuilder AddCoreNotifications(this IUmbracoBuilder builder)
{
// add handlers for sending user notifications (i.e. emails)
- builder.Services.AddUnique();
+ builder.Services.AddSingleton();
builder
.AddNotificationHandler()
.AddNotificationHandler()
diff --git a/src/Umbraco.Infrastructure/Mail/EmailSender.cs b/src/Umbraco.Infrastructure/Mail/EmailSender.cs
index 95be66e063..e5fbde2aac 100644
--- a/src/Umbraco.Infrastructure/Mail/EmailSender.cs
+++ b/src/Umbraco.Infrastructure/Mail/EmailSender.cs
@@ -30,18 +30,19 @@ namespace Umbraco.Cms.Infrastructure.Mail
ILogger logger,
IOptions globalSettings,
IEventAggregator eventAggregator)
- : this(logger, globalSettings, eventAggregator, null) { }
+ : this(logger, globalSettings, eventAggregator, null, null) { }
public EmailSender(
ILogger logger,
IOptions globalSettings,
IEventAggregator eventAggregator,
- INotificationHandler handler)
+ INotificationHandler handler1,
+ INotificationAsyncHandler handler2)
{
_logger = logger;
_eventAggregator = eventAggregator;
_globalSettings = globalSettings.Value;
- _notificationHandlerRegistered = handler is not null;
+ _notificationHandlerRegistered = handler1 is not null || handler2 is not null;
}
///