Example #1
0
        private Task PublishNotificationAsync(INotification notification, CancellationToken cancellationToken = default)
        {
            Type notificationType = notification.GetType();
            NotificationAsyncHandlerWrapper asyncHandler = s_notificationAsyncHandlers.GetOrAdd(
                notificationType,
                t => (NotificationAsyncHandlerWrapper)Activator.CreateInstance(typeof(NotificationAsyncHandlerWrapperImpl <>).MakeGenericType(notificationType)));

            return(asyncHandler.HandleAsync(notification, cancellationToken, _serviceFactory, PublishCoreAsync));
        }
Example #2
0
        private Task PublishNotificationAsync(INotification notification, CancellationToken cancellationToken = default)
        {
            Type notificationType = notification.GetType();
            NotificationAsyncHandlerWrapper asyncHandler = s_notificationAsyncHandlers.GetOrAdd(
                notificationType,
                t =>
            {
                var value = Activator.CreateInstance(
                    typeof(NotificationAsyncHandlerWrapperImpl <>).MakeGenericType(notificationType));
                return(value is not null
                        ? (NotificationAsyncHandlerWrapper)value
                        : throw new InvalidCastException("Activator could not create instance of NotificationHandler"));
            });

            return(asyncHandler.HandleAsync(notification, cancellationToken, _serviceFactory, PublishCoreAsync));
        }