Added support for sync notification handlers in the event aggregator
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Umbraco.Core.Events;
|
||||
|
||||
namespace Umbraco.Core.DependencyInjection
|
||||
@@ -35,5 +34,29 @@ namespace Umbraco.Core.DependencyInjection
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a notification async handler against the Umbraco service collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TNotification">The type of notification.</typeparam>
|
||||
/// <typeparam name="TNotificationAsyncHandler">The type of notification async handler.</typeparam>
|
||||
/// <param name="builder">The Umbraco builder.</param>
|
||||
/// <returns>The <see cref="IUmbracoBuilder"/>.</returns>
|
||||
public static IUmbracoBuilder AddNotificationAsyncHandler<TNotification, TNotificationAsyncHandler>(this IUmbracoBuilder builder)
|
||||
where TNotificationAsyncHandler : INotificationAsyncHandler<TNotification>
|
||||
where TNotification : INotification
|
||||
{
|
||||
// Register the handler as transient. This ensures that anything can be injected into it.
|
||||
var descriptor = new ServiceDescriptor(typeof(INotificationAsyncHandler<TNotification>), typeof(TNotificationAsyncHandler), ServiceLifetime.Transient);
|
||||
|
||||
// TODO: Waiting on feedback here https://github.com/umbraco/Umbraco-CMS/pull/9556/files#r548365396 about whether
|
||||
// we perform this duplicate check or not.
|
||||
if (!builder.Services.Contains(descriptor))
|
||||
{
|
||||
builder.Services.Add(descriptor);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Umbraco.Core.DependencyInjection
|
||||
|
||||
Services.AddSingleton<ManifestWatcher>();
|
||||
Services.AddSingleton<UmbracoRequestPaths>();
|
||||
this.AddNotificationHandler<UmbracoApplicationStarting, AppPluginsManifestWatcherNotificationHandler>();
|
||||
this.AddNotificationAsyncHandler<UmbracoApplicationStarting, AppPluginsManifestWatcherNotificationHandler>();
|
||||
|
||||
Services.AddUnique<InstallStatusTracker>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user