更新框架

This commit is contained in:
chfei committed 2026-10-27 14:35:03 +08:00
1 parent ef50fa0620
commit 84b28f9672
72 files changed
+2222 -282

No files matched your search

@@ -0,0 +1,15 @@
using Autofac;
namespace MAX.Core.Infrastructure;
/// <summary>
/// 将通知发布器的服务解析委托给当前 Autofac 作用域,无须引入额外适配包。
/// </summary>
internal sealed class AutofacNotificationServiceProvider(ILifetimeScope scope) : IServiceProvider
{
public object? GetService(Type serviceType)
{
ArgumentNullException.ThrowIfNull(serviceType);
return scope.ResolveOptional(serviceType);
}
}
@@ -1,32 +0,0 @@
using System.Collections.Generic;
namespace MAX.Core.Infrastructure;
public class Bootstrap//Bootstrap
{
public Bootstrap()
{
}
private readonly List<IBootstrap> _listUse = [];
public static Bootstrap Create()
{
return new Bootstrap();
}
public void UseMiddleware<T>() where T : IBootstrap, new()
{
T t = new();
t.Use();
_listUse.Add(t);
}
public void Builder()
{
foreach (IBootstrap item in _listUse)
{
item.Build();
}
}
}
@@ -1,7 +0,0 @@
namespace MAX.Core.Infrastructure;
public interface IBootstrap
{
void Use();
void Build();
}
@@ -1,18 +1,15 @@
using MAX.Core.Autofac;
using MediatR;
using Microsoft.Win32;
using MAX.Core.Autofac;
using MAX.Notification;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MAX.Core.Infrastructure;
public class MediatorManager : Mediator
public class MediatorManager : NotificationPublisher
{
private readonly DynamicNotificationHandlerRegistry _registry;
@@ -24,11 +21,11 @@ public class MediatorManager : Mediator
}
}
public MediatorManager(ServiceFactory serviceFactory) : base(serviceFactory)
public MediatorManager(IServiceProvider serviceProvider) : base(serviceProvider)
{
_registry = new DynamicNotificationHandlerRegistry();
}
protected override async Task PublishCore(IEnumerable<Func<INotification, CancellationToken, Task>> allHandlers, INotification notification, CancellationToken cancellationToken)
protected override async Task PublishCore(IEnumerable<NotificationHandlerExecutor> allHandlers, INotification notification, CancellationToken cancellationToken)
{
await base.PublishCore(allHandlers, notification, cancellationToken);
@@ -47,7 +44,7 @@ class DynamicNotificationHandlerRegistry
public DynamicNotificationHandlerRegistry()
{
}
// Key: notification type, Value: 已注册的 handler 调用委托列表
// 按通知类型保存动态注册的处理器调用委托。
private readonly ConcurrentDictionary<Type, List<Func<INotification, CancellationToken, Task>>>
_handlers = new();
@@ -82,7 +79,7 @@ class DynamicNotificationHandlerRegistry
}
}
/// <summary>Publish 时由 PluginAwareMediator 调用</summary>
/// <summary>发布通知时调用动态处理器。</summary>
public async Task Publish(INotification notification, CancellationToken cancellationToken)
{
var notificationType = notification.GetType();