通知处理程序在 .NET-Core 中 mediator.publish 后不接收通知

Notification Handler don't receiving notification after mediator.publish in .NET-Core

我创建了一个名为 SendMail 的通知 class,如下所示:

 public class SendMail : INotification
    {
        public string From { get; set; }
        public string To { get; set; }
        public string Subject { get; set; }
        public string Message { get; set; }
    }

之后,我实现了 SendMailNotificationHandler:

public class SendMailNotificationHandler: INotificationHandler<SendMail>
    {
        public Task Handle(SendMail notification, CancellationToken cancellationToken)
        {
            Console.WriteLine("Testing");

            return Task.CompletedTask;
        }

最后我在我的 RequestHandler 中执行了在系统中发布通知的程序:

public Task<OperationResult> Handle(CreateMailRequest request, CancellationToken cancellationToken)
        {
            // Just for example
            _repo.Insert(anything);

            _mediator.Publish(new SendMail
            {
                From = "test@test.com",
                To = "test@test.com",
                Subject = "New message",
                Message = "New test message"
            }, cancellationToken);


            return OperationResult.Success().AsTask;
        }

问题是,在调试时我看到发布方法是 运行,但 NotificationHandler 从未捕获到创建新邮件的通知。
我不知道发生了什么。有人可以帮忙吗?

问题出在我的 SimpleInjectorBootstrap.cs 上。我必须在我的 GetAssemblies 方法中添加以下代码:

private static IEnumerable<Assembly> GetAssemblies()
        {
            yield return typeof(ExceptionPipelineBehavior<,>).GetTypeInfo().Assembly;

            //added line
            yield return typeof(ReportCreatedNotificationHandler).GetTypeInfo().Assembly;
        }