-
Notifications
You must be signed in to change notification settings - Fork 3
feat(cqrs): 添加CQRS运行时模块和兼容性扩展 #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GeWuYou
merged 12 commits into
refactor/cqrs-architecture-decoupling
from
refactor/cqrs-architecture-decoupling-todo-6
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a80ff59
feat(cqrs): 添加CQRS运行时模块和兼容性扩展
GeWuYou e36c802
feat(cqrs): 添加CQRS处理器基类和测试运行时支持
GeWuYou 1c7558a
refactor(cqrs): 移除旧日志行为并添加CQRS运行时模块
GeWuYou 18337c5
refactor(tests): 移除未使用的 System.Diagnostics 引用
GeWuYou 005c32d
feat(cqrs): 添加CQRS扩展方法兼容层和日志工厂解析器
GeWuYou 12c9c8a
refactor(cqrs): 迁移CQRS基础类型实现并维护程序集兼容性
GeWuYou b747787
refactor(core): 更新类型转发器和测试文件的命名空间引用
GeWuYou 7e402d9
docs(cqrs): 修正泛型类型参数的XML文档注释
GeWuYou 7a2127b
refactor(cqrs): 更新Cqrs命名空间路径
GeWuYou ff9b010
refactor(cqrs): 调整基础消息类型的命名空间和程序集布局
GeWuYou 7b63a65
refactor(tests): 重构CQRS类型转发测试以使用新命名空间
GeWuYou 922ad43
fix(cqrs): 修复CQRS命名空间兼容性测试中的类型解析问题
GeWuYou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
281 changes: 281 additions & 0 deletions
281
GFramework.Core.Abstractions/Logging/LoggerFactoryResolver.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,281 @@ | ||
| namespace GFramework.Core.Abstractions.Logging; | ||
|
|
||
| /// <summary> | ||
| /// 提供全局日志工厂访问入口。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// 该类型位于抽象层,是为了让上层模块可以在不依赖 <c>GFramework.Core</c> 实现程序集的前提下 | ||
| /// 获取日志记录器。默认 provider 会优先通过反射解析 <c>GFramework.Core</c> 中的控制台实现, | ||
| /// 若宿主未加载该程序集,则退回到静默 provider,避免抽象层形成实现层循环依赖。 | ||
| /// </remarks> | ||
| public static class LoggerFactoryResolver | ||
| { | ||
| private static readonly object ProviderLock = new(); | ||
|
|
||
| private static string DefaultProviderTypeName = | ||
| "GFramework.Core.Logging.ConsoleLoggerFactoryProvider, GFramework.Core"; | ||
|
|
||
| private static ILoggerFactoryProvider? _provider; | ||
|
|
||
| /// <summary> | ||
| /// 获取或设置当前日志工厂提供程序。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// 读取与赋值都会通过同一把锁串行化,确保并发调用方观察到确定的 provider 引用。 | ||
| /// 当调用方未显式赋值时,会在首次访问时尝试解析默认实现;若解析失败,则退回静默 provider。 | ||
| /// </remarks> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// 当赋值为 <see langword="null" /> 时抛出。 | ||
| /// </exception> | ||
| public static ILoggerFactoryProvider Provider | ||
| { | ||
| get | ||
| { | ||
| lock (ProviderLock) | ||
| { | ||
| _provider ??= CreateDefaultProvider(); | ||
| return _provider; | ||
| } | ||
| } | ||
| set | ||
| { | ||
| var provider = value ?? throw new ArgumentNullException(nameof(value)); | ||
|
|
||
| lock (ProviderLock) | ||
| { | ||
| _provider = provider; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 获取或设置新创建日志记录器的最小日志级别。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// 该属性直接代理到当前 <see cref="Provider" />,确保调用方调整级别后立即影响后续创建的日志器。 | ||
| /// </remarks> | ||
| public static LogLevel MinLevel | ||
| { | ||
| get => Provider.MinLevel; | ||
| set => Provider.MinLevel = value; | ||
| } | ||
|
|
||
| private static ILoggerFactoryProvider CreateDefaultProvider() | ||
| { | ||
| try | ||
| { | ||
| if (Type.GetType(DefaultProviderTypeName, throwOnError: false) is { } providerType && | ||
| Activator.CreateInstance(providerType) is ILoggerFactoryProvider provider) | ||
| { | ||
| provider.MinLevel = LogLevel.Info; | ||
| return provider; | ||
| } | ||
| } | ||
| catch (Exception) | ||
| { | ||
| // The default provider is optional. Any load or activation failure must degrade to the silent provider so | ||
| // abstractions-only hosts can continue bootstrapping without the concrete logging assembly. | ||
| } | ||
|
|
||
| return new SilentLoggerFactoryProvider(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// 当宿主未提供默认日志实现时使用的静默 provider。 | ||
| /// </summary> | ||
| private sealed class SilentLoggerFactoryProvider : ILoggerFactoryProvider | ||
| { | ||
| public LogLevel MinLevel { get; set; } = LogLevel.Info; | ||
|
|
||
| public ILogger CreateLogger(string name) | ||
| { | ||
| return new SilentLogger(name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 默认日志实现不可用时的 no-op 日志器。 | ||
| /// </summary> | ||
| private sealed class SilentLogger(string name) : ILogger | ||
| { | ||
| public string Name() | ||
| { | ||
| return name; | ||
| } | ||
|
|
||
| public bool IsTraceEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsDebugEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsInfoEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsWarnEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsErrorEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsFatalEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public bool IsEnabledForLevel(LogLevel level) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public void Trace(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Trace(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Trace(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Trace(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Trace(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Debug(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Debug(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Debug(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Debug(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Debug(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Info(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Info(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Info(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Info(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Info(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Warn(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Warn(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Warn(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Warn(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Warn(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Error(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Error(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Error(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Error(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Error(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Fatal(string msg) | ||
| { | ||
| } | ||
|
|
||
| public void Fatal(string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Fatal(string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Fatal(string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Fatal(string msg, Exception t) | ||
| { | ||
| } | ||
|
|
||
| public void Log(LogLevel level, string message) | ||
| { | ||
| } | ||
|
|
||
| public void Log(LogLevel level, string format, object arg) | ||
| { | ||
| } | ||
|
|
||
| public void Log(LogLevel level, string format, object arg1, object arg2) | ||
| { | ||
| } | ||
|
|
||
| public void Log(LogLevel level, string format, params object[] arguments) | ||
| { | ||
| } | ||
|
|
||
| public void Log(LogLevel level, string message, Exception exception) | ||
| { | ||
| } | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
GFramework.Core.Tests/Architectures/ArchitectureAdditionalCqrsHandlersTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
GFramework.Core.Tests/Architectures/ArchitectureModulesBehaviorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.