using System; using GFramework.Core.Abstractions.Logging; using GFramework.Core.Ioc; using GFramework.Core.Logging; using GFramework.Cqrs.Abstractions.Cqrs; namespace GFramework.Cqrs.Tests.Cqrs; /// /// 模拟生成注册器使用私有无参构造器的场景,验证运行时仍可通过缓存工厂激活它。 /// internal sealed class PrivateConstructorNotificationHandlerRegistry : ICqrsHandlerRegistry { /// /// 初始化一个新的私有生成注册器实例。 /// private PrivateConstructorNotificationHandlerRegistry() { } /// /// 将测试通知处理器注册到目标服务集合。 /// /// 承载处理器映射的服务集合。 /// 用于记录注册诊断的日志器。 public void Register(IServiceCollection services, ILogger logger) { ArgumentNullException.ThrowIfNull(services); ArgumentNullException.ThrowIfNull(logger); services.AddTransient( typeof(INotificationHandler), typeof(GeneratedRegistryNotificationHandler)); logger.Debug( $"Registered CQRS handler {typeof(GeneratedRegistryNotificationHandler).FullName} as {typeof(INotificationHandler).FullName}."); } }