更新框架
This commit is contained in:
1 parent
ef50fa0620
commit
84b28f9672
72 files changed
+2222
-282
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// 摘自 MediatR 14.2.0,许可声明与修改记录见 LICENSE.md 和 UPSTREAM.md。
|
||||
namespace MAX.Notification.Wrappers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
public abstract class NotificationHandlerWrapper
|
||||
{
|
||||
public abstract Task Handle(INotification notification, IServiceProvider serviceFactory,
|
||||
Func<IEnumerable<NotificationHandlerExecutor>, INotification, CancellationToken, Task> publish,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public class NotificationHandlerWrapperImpl<TNotification> : NotificationHandlerWrapper
|
||||
where TNotification : INotification
|
||||
{
|
||||
public override Task Handle(INotification notification, IServiceProvider serviceFactory,
|
||||
Func<IEnumerable<NotificationHandlerExecutor>, INotification, CancellationToken, Task> publish,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var handlers = ((IEnumerable<INotificationHandler<TNotification>>?)serviceFactory.GetService(typeof(IEnumerable<INotificationHandler<TNotification>>)) ?? Array.Empty<INotificationHandler<TNotification>>())
|
||||
.GroupBy(static x => x.GetType())
|
||||
.Select(static g => g.First())
|
||||
.Select(static x => new NotificationHandlerExecutor(x, (theNotification, theToken) => x.Handle((TNotification)theNotification, theToken)));
|
||||
|
||||
return publish(handlers, notification, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user