// 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. var descriptor = new ServiceDescriptor(typeof(INotificationHandler), typeof(TNotificationHandler), 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; } /// /// Registers a notification async handler against the Umbraco service collection. /// /// The type of notification. /// The type of notification async handler. /// The Umbraco builder. /// The . public static IUmbracoBuilder AddNotificationAsyncHandler(this IUmbracoBuilder builder) where TNotificationAsyncHandler : INotificationAsyncHandler where TNotification : INotification { // Register the handler as transient. This ensures that anything can be injected into it. var descriptor = new ServiceDescriptor(typeof(INotificationAsyncHandler), 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; } } }