-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor/cqrs architecture decoupling todo 7 #226
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 6 commits into
refactor/cqrs-architecture-decoupling
from
refactor/cqrs-architecture-decoupling-todo-7
Apr 16, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1973fb2
feat(ioc): 添加Microsoft DI容器适配器和CQRS运行时模块
GeWuYou a7604de
feat(ioc): 添加 Microsoft DI 容器适配器和 CQRS 运行时模块
GeWuYou bc93364
feat(cqrs): 添加 CQRS 处理器注册器和源码生成器
GeWuYou 00a1038
refactor(GFramework.Cqrs): 添加全局using引用System.Reflection
GeWuYou 0d9d09b
feat(ioc): 添加Microsoft DI容器适配器及测试
GeWuYou a4dfc78
feat(ioc): 添加Microsoft DI容器适配器及测试
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
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 |
|---|---|---|
| @@ -1,52 +1,16 @@ | ||
| using GFramework.Core.Abstractions.Architectures; | ||
| using GFramework.Cqrs.Abstractions.Cqrs; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace GFramework.Core.Abstractions.Cqrs; | ||
|
|
||
| /// <summary> | ||
| /// 定义架构上下文使用的 CQRS runtime seam。 | ||
| /// 该抽象把请求分发、通知发布与流式处理从具体实现中解耦, | ||
| /// 使 <see cref="IArchitectureContext" /> 不再直接依赖某个固定的 runtime 类型。 | ||
| /// 提供旧 <c>GFramework.Core.Abstractions.Cqrs</c> 命名空间下的 CQRS runtime 兼容别名。 | ||
| /// </summary> | ||
| public interface ICqrsRuntime | ||
| /// <remarks> | ||
| /// 正式 runtime seam 已迁移到 <see cref="GFramework.Cqrs.Abstractions.Cqrs.ICqrsRuntime" />, | ||
| /// 但当前仍保留该接口以避免立即打断历史公开路径与既有二进制引用。 | ||
| /// 新代码应优先依赖 <c>GFramework.Cqrs.Abstractions.Cqrs</c> 下的正式契约。 | ||
| /// </remarks> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public interface ICqrsRuntime : GFramework.Cqrs.Abstractions.Cqrs.ICqrsRuntime | ||
| { | ||
| /// <summary> | ||
| /// 发送请求并返回响应。 | ||
| /// </summary> | ||
| /// <typeparam name="TResponse">响应类型。</typeparam> | ||
| /// <param name="context">当前架构上下文,用于上下文感知处理器注入与嵌套请求访问。</param> | ||
| /// <param name="request">要分发的请求。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>请求响应。</returns> | ||
| ValueTask<TResponse> SendAsync<TResponse>( | ||
| IArchitectureContext context, | ||
| IRequest<TResponse> request, | ||
| CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// 发布通知到所有已注册处理器。 | ||
| /// </summary> | ||
| /// <typeparam name="TNotification">通知类型。</typeparam> | ||
| /// <param name="context">当前架构上下文,用于上下文感知处理器注入。</param> | ||
| /// <param name="notification">要发布的通知。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>表示通知分发完成的值任务。</returns> | ||
| ValueTask PublishAsync<TNotification>( | ||
| IArchitectureContext context, | ||
| TNotification notification, | ||
| CancellationToken cancellationToken = default) | ||
| where TNotification : INotification; | ||
|
|
||
| /// <summary> | ||
| /// 创建流式请求的异步响应序列。 | ||
| /// </summary> | ||
| /// <typeparam name="TResponse">流元素类型。</typeparam> | ||
| /// <param name="context">当前架构上下文,用于上下文感知处理器注入。</param> | ||
| /// <param name="request">流式请求。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>按需生成的异步响应序列。</returns> | ||
| IAsyncEnumerable<TResponse> CreateStream<TResponse>( | ||
| IArchitectureContext context, | ||
| IStreamRequest<TResponse> request, | ||
| CancellationToken cancellationToken = default); | ||
| } |
1 change: 0 additions & 1 deletion
1
GFramework.Core.Tests/Architectures/ArchitectureContextTests.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
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,13 @@ | ||
| namespace GFramework.Cqrs.Abstractions.Cqrs; | ||
|
|
||
| /// <summary> | ||
| /// 定义 CQRS runtime 在分发期间携带的最小上下文标记。 | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// 该接口当前刻意保持为轻量 marker seam,只用于让 <see cref="ICqrsRuntime" /> 从 | ||
| /// <c>GFramework.Core.Abstractions</c> 的 <c>IArchitectureContext</c> 解耦。 | ||
| /// 运行时实现仍可在需要时识别更具体的上下文类型,并对现有 <c>IContextAware</c> 处理器执行兼容注入。 | ||
| /// </remarks> | ||
| public interface ICqrsContext | ||
| { | ||
| } |
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,49 @@ | ||
| namespace GFramework.Cqrs.Abstractions.Cqrs; | ||
|
|
||
| /// <summary> | ||
| /// 定义架构上下文使用的 CQRS runtime seam。 | ||
| /// 该抽象把请求分发、通知发布与流式处理从具体实现中解耦, | ||
| /// 使 CQRS runtime 契约可独立归属到 <c>GFramework.Cqrs.Abstractions</c>。 | ||
| /// </summary> | ||
| public interface ICqrsRuntime | ||
| { | ||
| /// <summary> | ||
| /// 发送请求并返回响应。 | ||
| /// </summary> | ||
| /// <typeparam name="TResponse">响应类型。</typeparam> | ||
| /// <param name="context">当前 CQRS 分发上下文。</param> | ||
| /// <param name="request">要分发的请求。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>请求响应。</returns> | ||
| ValueTask<TResponse> SendAsync<TResponse>( | ||
| ICqrsContext context, | ||
| IRequest<TResponse> request, | ||
| CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// 发布通知到所有已注册处理器。 | ||
| /// </summary> | ||
| /// <typeparam name="TNotification">通知类型。</typeparam> | ||
| /// <param name="context">当前 CQRS 分发上下文。</param> | ||
| /// <param name="notification">要发布的通知。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>表示通知分发完成的值任务。</returns> | ||
| ValueTask PublishAsync<TNotification>( | ||
| ICqrsContext context, | ||
| TNotification notification, | ||
| CancellationToken cancellationToken = default) | ||
| where TNotification : INotification; | ||
|
|
||
| /// <summary> | ||
| /// 创建流式请求的异步响应序列。 | ||
| /// </summary> | ||
| /// <typeparam name="TResponse">流元素类型。</typeparam> | ||
| /// <param name="context">当前 CQRS 分发上下文。</param> | ||
| /// <param name="request">流式请求。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>按需生成的异步响应序列。</returns> | ||
| IAsyncEnumerable<TResponse> CreateStream<TResponse>( | ||
| ICqrsContext context, | ||
| IStreamRequest<TResponse> request, | ||
| CancellationToken cancellationToken = default); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 5601
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 214
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 217
🏁 Script executed:
# 查看整个 MicrosoftDiContainer 类以了解其 API wc -l GFramework.Core/Ioc/MicrosoftDiContainer.csRepository: GeWuYou/GFramework
Length of output: 109
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 493
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 549
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 44
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 44
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 217
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 711
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 2050
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 787
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 118
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 454
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 455
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 44
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 678
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 483
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 621
🏁 Script executed:
Repository: GeWuYou/GFramework
Length of output: 1210
ResolveCqrsRegistrationService()只检查实例绑定,但容器公开 API 允许其他注册方式。容器支持
RegisterSingleton<TService, TImpl>()和RegisterFactory<TService>()作为公开 API,但此方法仅检查descriptor?.ImplementationInstance。如果用户通过这些 API 注册ICqrsRegistrationService(即使是合法的用法),也会触发"not registered"错误。虽然当前官方模块(
CqrsRuntimeModule)只用实例方式注册,注释也说明了这是有意的设计(避免在容器未冻结时完整构建),但这个约束应该更显式地防守或文档化。建议:CqrsRuntimeModule和相关文档中明确标注ICqrsRegistrationService只能通过实例注册🤖 Prompt for AI Agents