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)); }
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)); }