feat(architecture): 添加批量获取组件实例的功能#69
Merged
Merged
Conversation
- 在 ArchitectureContext 中添加 GetServices、GetSystems、GetModels 和 GetUtilities 方法 - 扩展 IArchitectureContext 接口以支持批量获取各类组件实例 - 在测试类中实现相应的批量获取功能 - 将原有的 ContextAwareExtensions 拆分为多个专门的扩展类文件 - 新增 ContextAwareCommandExtensions、ContextAwareEnvironmentExtensions 和 ContextAwareEventExtensions 等扩展类 - 提供了更完善的架构上下文组件访问能力
Reviewer's Guide为架构上下文组件(服务、系统、模型、工具)引入批量检索 API,并将原有的上下文感知扩展方法重构为聚焦的扩展类,分别为服务、环境访问和事件处理提供专用的单元测试。 通过 ContextAwareServiceExtensions.GetServices 进行批量检索的时序图sequenceDiagram
actor Client
participant ContextAwareObject
participant ContextAwareServiceExtensions
participant IArchitectureContext
participant ArchitectureContext
participant IContainer
Client->>ContextAwareObject: Call GetServices~TestService~()
ContextAwareObject->>ContextAwareServiceExtensions: GetServices~TestService~(this)
ContextAwareServiceExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareServiceExtensions: IArchitectureContext
ContextAwareServiceExtensions->>IArchitectureContext: GetServices~TestService~()
IArchitectureContext->>ArchitectureContext: GetServices~TestService~()
ArchitectureContext->>IContainer: GetAll~TestService~()
IContainer-->>ArchitectureContext: IReadOnlyList~TestService~
ArchitectureContext-->>IArchitectureContext: IReadOnlyList~TestService~
IArchitectureContext-->>ContextAwareServiceExtensions: IReadOnlyList~TestService~
ContextAwareServiceExtensions-->>ContextAwareObject: IReadOnlyList~TestService~
ContextAwareObject-->>Client: IReadOnlyList~TestService~
通过 ContextAwareEventExtensions 进行事件发送与处理器注册的时序图sequenceDiagram
actor Client
participant ContextAwareObject
participant ContextAwareEventExtensions
participant IArchitectureContext
participant ArchitectureContext
participant IEventBus
Client->>ContextAwareObject: RegisterEvent~TestEvent~(handler)
ContextAwareObject->>ContextAwareEventExtensions: RegisterEvent~TestEvent~(this, handler)
ContextAwareEventExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareEventExtensions: IArchitectureContext
ContextAwareEventExtensions->>IArchitectureContext: RegisterEvent~TestEvent~(handler)
IArchitectureContext->>ArchitectureContext: RegisterEvent~TestEvent~(handler)
ArchitectureContext->>IEventBus: Register~TestEvent~(handler)
IEventBus-->>ArchitectureContext: IUnRegister
ArchitectureContext-->>IArchitectureContext: IUnRegister
IArchitectureContext-->>ContextAwareEventExtensions: IUnRegister
ContextAwareEventExtensions-->>ContextAwareObject: IUnRegister
ContextAwareObject-->>Client: IUnRegister
Client->>ContextAwareObject: SendEvent(new TestEvent)
ContextAwareObject->>ContextAwareEventExtensions: SendEvent~TestEvent~(this, event)
ContextAwareEventExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareEventExtensions: IArchitectureContext
ContextAwareEventExtensions->>IArchitectureContext: SendEvent~TestEvent~(event)
IArchitectureContext->>ArchitectureContext: SendEvent~TestEvent~(event)
ArchitectureContext->>IEventBus: Publish~TestEvent~(event)
IEventBus-->>ArchitectureContext: Dispatch to handler
ArchitectureContext-->>IArchitectureContext: return
IArchitectureContext-->>ContextAwareEventExtensions: return
ContextAwareEventExtensions-->>ContextAwareObject: return
ContextAwareObject-->>Client: return
更新后的 IArchitectureContext 批量检索 API 类图classDiagram
class IArchitectureContext {
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
+void SendEvent~TEvent~()
+void SendEvent~TEvent~(TEvent e)
+IUnRegister RegisterEvent~TEvent~(Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(Action~TEvent~ handler)
+IEnvironment GetEnvironment()
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IRequest~TResponse~ command, CancellationToken cancellationToken)
+TResponse SendCommand~TResponse~(Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(ICommand~TResult~ command)
+void SendCommand(ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IAsyncCommand~TResult~ command)
+TResponse SendQuery~TResponse~(Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IAsyncQuery~TResult~ query)
}
class ArchitectureContext {
-IContainer _container
+ArchitectureContext(IContainer container)
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
+void SendEvent~TEvent~()
+void SendEvent~TEvent~(TEvent e)
+IUnRegister RegisterEvent~TEvent~(Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(Action~TEvent~ handler)
+IEnvironment GetEnvironment()
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IRequest~TResponse~ command, CancellationToken cancellationToken)
+TResponse SendCommand~TResponse~(Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(ICommand~TResult~ command)
+void SendCommand(ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IAsyncCommand~TResult~ command)
+TResponse SendQuery~TResponse~(Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IAsyncQuery~TResult~ query)
}
class TestArchitectureContext {
-IContainer _container
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
}
class TestArchitectureContextV3 {
-IContainer _container
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
}
class IContainer {
+T Get~T~()
+IReadOnlyList~T~ GetAll~T~()
+void Register~T~(T instance)
+void RegisterSystem(ISystem system)
+void Freeze()
+void Clear()
}
IArchitectureContext <|.. ArchitectureContext
IArchitectureContext <|.. TestArchitectureContext
IArchitectureContext <|.. TestArchitectureContextV3
ArchitectureContext o-- IContainer
TestArchitectureContext o-- IContainer
TestArchitectureContextV3 o-- IContainer
class ISystem
class IModel
class IUtility
class IEnvironment
class IUnRegister
class IRequest~TResponse~
class INotification
class IStreamRequest~TResponse~
class ICommand
class ICommand~TResult~
class IAsyncCommand
class IAsyncCommand~TResult~
class IQuery~TResult~
class IAsyncQuery~TResult~
class Mediator_ICommand~TResponse~
class Mediator_IQuery~TResponse~
ArchitectureContext ..> ISystem
ArchitectureContext ..> IModel
ArchitectureContext ..> IUtility
ArchitectureContext ..> IEnvironment
ArchitectureContext ..> IRequest~TResponse~
ArchitectureContext ..> INotification
ArchitectureContext ..> IStreamRequest~TResponse~
ArchitectureContext ..> ICommand
ArchitectureContext ..> ICommand~TResult~
ArchitectureContext ..> IAsyncCommand
ArchitectureContext ..> IAsyncCommand~TResult~
ArchitectureContext ..> IQuery~TResult~
ArchitectureContext ..> IAsyncQuery~TResult~
ArchitectureContext ..> Mediator_ICommand~TResponse~
ArchitectureContext ..> Mediator_IQuery~TResponse~
上下文感知扩展重构的类图classDiagram
class IContextAware {
+void SetContext(IArchitectureContext context)
+IArchitectureContext GetContext()
}
class ContextAwareBase {
-IArchitectureContext _context
+void SetContext(IArchitectureContext context)
+IArchitectureContext GetContext()
}
IContextAware <|.. ContextAwareBase
class ContextAwareServiceExtensions {
<<static>>
+TService GetService~TService~(IContextAware contextAware)
+TSystem GetSystem~TSystem~(IContextAware contextAware)
+TModel GetModel~TModel~(IContextAware contextAware)
+TUtility GetUtility~TUtility~(IContextAware contextAware)
+IReadOnlyList~TService~ GetServices~TService~(IContextAware contextAware)
+IReadOnlyList~TSystem~ GetSystems~TSystem~(IContextAware contextAware)
+IReadOnlyList~TModel~ GetModels~TModel~(IContextAware contextAware)
+IReadOnlyList~TUtility~ GetUtilities~TUtility~(IContextAware contextAware)
}
class ContextAwareEnvironmentExtensions {
<<static>>
+T GetEnvironment~T~(IContextAware contextAware)
+IEnvironment GetEnvironment(IContextAware contextAware)
}
class ContextAwareEventExtensions {
<<static>>
+void SendEvent~TEvent~(IContextAware contextAware)
+void SendEvent~TEvent~(IContextAware contextAware, TEvent e)
+IUnRegister RegisterEvent~TEvent~(IContextAware contextAware, Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(IContextAware contextAware, Action~TEvent~ onEvent)
}
class ContextAwareMediatorExtensions {
<<static>>
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IContextAware contextAware, IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IContextAware contextAware, IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(IContextAware contextAware, TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IContextAware contextAware, IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(IContextAware contextAware, TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IContextAware contextAware, IRequest~TResponse~ command, CancellationToken cancellationToken)
}
class ContextAwareCommandExtensions {
<<static>>
+TResponse SendCommand~TResponse~(IContextAware contextAware, Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(IContextAware contextAware, ICommand~TResult~ command)
+void SendCommand(IContextAware contextAware, ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(IContextAware contextAware, Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IContextAware contextAware, IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IContextAware contextAware, IAsyncCommand~TResult~ command)
}
class ContextAwareQueryExtensions {
<<static>>
+TResponse SendQuery~TResponse~(IContextAware contextAware, Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IContextAware contextAware, IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(IContextAware contextAware, Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IContextAware contextAware, IAsyncQuery~TResult~ query)
}
class IArchitectureContext
class IEnvironment
class IEventBus {
+void Publish~TEvent~(TEvent e)
+IUnRegister Register~TEvent~(Action~TEvent~ handler)
+void UnRegister~TEvent~(Action~TEvent~ handler)
}
class EventBus {
+void Publish~TEvent~(TEvent e)
+IUnRegister Register~TEvent~(Action~TEvent~ handler)
+void UnRegister~TEvent~(Action~TEvent~ handler)
}
class IUnRegister {
+void UnRegister()
}
class IRequest~TResponse~
class IStreamRequest~TResponse~
class Mediator_ICommand~TResponse~
class Mediator_IQuery~TResponse~
class ICommand
class ICommand~TResult~
class IAsyncCommand
class IAsyncCommand~TResult~
class IQuery~TResult~
class IAsyncQuery~TResult~
ContextAwareServiceExtensions ..> IContextAware
ContextAwareServiceExtensions ..> IArchitectureContext
ContextAwareEnvironmentExtensions ..> IContextAware
ContextAwareEnvironmentExtensions ..> IArchitectureContext
ContextAwareEnvironmentExtensions ..> IEnvironment
ContextAwareEventExtensions ..> IContextAware
ContextAwareEventExtensions ..> IArchitectureContext
ContextAwareEventExtensions ..> IUnRegister
ContextAwareMediatorExtensions ..> IContextAware
ContextAwareMediatorExtensions ..> IArchitectureContext
ContextAwareCommandExtensions ..> IContextAware
ContextAwareCommandExtensions ..> IArchitectureContext
ContextAwareQueryExtensions ..> IContextAware
ContextAwareQueryExtensions ..> IArchitectureContext
EventBus ..|> IEventBus
ContextAwareBase o-- IArchitectureContext
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideIntroduce batch retrieval APIs for architecture context components (services, systems, models, utilities), and refactor context-aware extension methods into focused extension classes with dedicated unit tests for services, environment access, and event handling. Sequence diagram for batch retrieval via ContextAwareServiceExtensions.GetServicessequenceDiagram
actor Client
participant ContextAwareObject
participant ContextAwareServiceExtensions
participant IArchitectureContext
participant ArchitectureContext
participant IContainer
Client->>ContextAwareObject: Call GetServices~TestService~()
ContextAwareObject->>ContextAwareServiceExtensions: GetServices~TestService~(this)
ContextAwareServiceExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareServiceExtensions: IArchitectureContext
ContextAwareServiceExtensions->>IArchitectureContext: GetServices~TestService~()
IArchitectureContext->>ArchitectureContext: GetServices~TestService~()
ArchitectureContext->>IContainer: GetAll~TestService~()
IContainer-->>ArchitectureContext: IReadOnlyList~TestService~
ArchitectureContext-->>IArchitectureContext: IReadOnlyList~TestService~
IArchitectureContext-->>ContextAwareServiceExtensions: IReadOnlyList~TestService~
ContextAwareServiceExtensions-->>ContextAwareObject: IReadOnlyList~TestService~
ContextAwareObject-->>Client: IReadOnlyList~TestService~
Sequence diagram for event send and handler registration via ContextAwareEventExtensionssequenceDiagram
actor Client
participant ContextAwareObject
participant ContextAwareEventExtensions
participant IArchitectureContext
participant ArchitectureContext
participant IEventBus
Client->>ContextAwareObject: RegisterEvent~TestEvent~(handler)
ContextAwareObject->>ContextAwareEventExtensions: RegisterEvent~TestEvent~(this, handler)
ContextAwareEventExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareEventExtensions: IArchitectureContext
ContextAwareEventExtensions->>IArchitectureContext: RegisterEvent~TestEvent~(handler)
IArchitectureContext->>ArchitectureContext: RegisterEvent~TestEvent~(handler)
ArchitectureContext->>IEventBus: Register~TestEvent~(handler)
IEventBus-->>ArchitectureContext: IUnRegister
ArchitectureContext-->>IArchitectureContext: IUnRegister
IArchitectureContext-->>ContextAwareEventExtensions: IUnRegister
ContextAwareEventExtensions-->>ContextAwareObject: IUnRegister
ContextAwareObject-->>Client: IUnRegister
Client->>ContextAwareObject: SendEvent(new TestEvent)
ContextAwareObject->>ContextAwareEventExtensions: SendEvent~TestEvent~(this, event)
ContextAwareEventExtensions->>ContextAwareObject: GetContext()
ContextAwareObject-->>ContextAwareEventExtensions: IArchitectureContext
ContextAwareEventExtensions->>IArchitectureContext: SendEvent~TestEvent~(event)
IArchitectureContext->>ArchitectureContext: SendEvent~TestEvent~(event)
ArchitectureContext->>IEventBus: Publish~TestEvent~(event)
IEventBus-->>ArchitectureContext: Dispatch to handler
ArchitectureContext-->>IArchitectureContext: return
IArchitectureContext-->>ContextAwareEventExtensions: return
ContextAwareEventExtensions-->>ContextAwareObject: return
ContextAwareObject-->>Client: return
Class diagram for updated IArchitectureContext batch retrieval APIsclassDiagram
class IArchitectureContext {
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
+void SendEvent~TEvent~()
+void SendEvent~TEvent~(TEvent e)
+IUnRegister RegisterEvent~TEvent~(Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(Action~TEvent~ handler)
+IEnvironment GetEnvironment()
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IRequest~TResponse~ command, CancellationToken cancellationToken)
+TResponse SendCommand~TResponse~(Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(ICommand~TResult~ command)
+void SendCommand(ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IAsyncCommand~TResult~ command)
+TResponse SendQuery~TResponse~(Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IAsyncQuery~TResult~ query)
}
class ArchitectureContext {
-IContainer _container
+ArchitectureContext(IContainer container)
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
+void SendEvent~TEvent~()
+void SendEvent~TEvent~(TEvent e)
+IUnRegister RegisterEvent~TEvent~(Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(Action~TEvent~ handler)
+IEnvironment GetEnvironment()
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IRequest~TResponse~ command, CancellationToken cancellationToken)
+TResponse SendCommand~TResponse~(Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(ICommand~TResult~ command)
+void SendCommand(ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IAsyncCommand~TResult~ command)
+TResponse SendQuery~TResponse~(Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IAsyncQuery~TResult~ query)
}
class TestArchitectureContext {
-IContainer _container
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
}
class TestArchitectureContextV3 {
-IContainer _container
+TService GetService~TService~()
+IReadOnlyList~TService~ GetServices~TService~()
+TSystem GetSystem~TSystem~()
+IReadOnlyList~TSystem~ GetSystems~TSystem~()
+TModel GetModel~TModel~()
+IReadOnlyList~TModel~ GetModels~TModel~()
+TUtility GetUtility~TUtility~()
+IReadOnlyList~TUtility~ GetUtilities~TUtility~()
}
class IContainer {
+T Get~T~()
+IReadOnlyList~T~ GetAll~T~()
+void Register~T~(T instance)
+void RegisterSystem(ISystem system)
+void Freeze()
+void Clear()
}
IArchitectureContext <|.. ArchitectureContext
IArchitectureContext <|.. TestArchitectureContext
IArchitectureContext <|.. TestArchitectureContextV3
ArchitectureContext o-- IContainer
TestArchitectureContext o-- IContainer
TestArchitectureContextV3 o-- IContainer
class ISystem
class IModel
class IUtility
class IEnvironment
class IUnRegister
class IRequest~TResponse~
class INotification
class IStreamRequest~TResponse~
class ICommand
class ICommand~TResult~
class IAsyncCommand
class IAsyncCommand~TResult~
class IQuery~TResult~
class IAsyncQuery~TResult~
class Mediator_ICommand~TResponse~
class Mediator_IQuery~TResponse~
ArchitectureContext ..> ISystem
ArchitectureContext ..> IModel
ArchitectureContext ..> IUtility
ArchitectureContext ..> IEnvironment
ArchitectureContext ..> IRequest~TResponse~
ArchitectureContext ..> INotification
ArchitectureContext ..> IStreamRequest~TResponse~
ArchitectureContext ..> ICommand
ArchitectureContext ..> ICommand~TResult~
ArchitectureContext ..> IAsyncCommand
ArchitectureContext ..> IAsyncCommand~TResult~
ArchitectureContext ..> IQuery~TResult~
ArchitectureContext ..> IAsyncQuery~TResult~
ArchitectureContext ..> Mediator_ICommand~TResponse~
ArchitectureContext ..> Mediator_IQuery~TResponse~
Class diagram for context-aware extension refactorclassDiagram
class IContextAware {
+void SetContext(IArchitectureContext context)
+IArchitectureContext GetContext()
}
class ContextAwareBase {
-IArchitectureContext _context
+void SetContext(IArchitectureContext context)
+IArchitectureContext GetContext()
}
IContextAware <|.. ContextAwareBase
class ContextAwareServiceExtensions {
<<static>>
+TService GetService~TService~(IContextAware contextAware)
+TSystem GetSystem~TSystem~(IContextAware contextAware)
+TModel GetModel~TModel~(IContextAware contextAware)
+TUtility GetUtility~TUtility~(IContextAware contextAware)
+IReadOnlyList~TService~ GetServices~TService~(IContextAware contextAware)
+IReadOnlyList~TSystem~ GetSystems~TSystem~(IContextAware contextAware)
+IReadOnlyList~TModel~ GetModels~TModel~(IContextAware contextAware)
+IReadOnlyList~TUtility~ GetUtilities~TUtility~(IContextAware contextAware)
}
class ContextAwareEnvironmentExtensions {
<<static>>
+T GetEnvironment~T~(IContextAware contextAware)
+IEnvironment GetEnvironment(IContextAware contextAware)
}
class ContextAwareEventExtensions {
<<static>>
+void SendEvent~TEvent~(IContextAware contextAware)
+void SendEvent~TEvent~(IContextAware contextAware, TEvent e)
+IUnRegister RegisterEvent~TEvent~(IContextAware contextAware, Action~TEvent~ handler)
+void UnRegisterEvent~TEvent~(IContextAware contextAware, Action~TEvent~ onEvent)
}
class ContextAwareMediatorExtensions {
<<static>>
+ValueTask~TResponse~ SendRequestAsync~TResponse~(IContextAware contextAware, IRequest~TResponse~ request, CancellationToken cancellationToken)
+TResponse SendRequest~TResponse~(IContextAware contextAware, IRequest~TResponse~ request)
+ValueTask PublishAsync~TNotification~(IContextAware contextAware, TNotification notification, CancellationToken cancellationToken)
+IAsyncEnumerable~TResponse~ CreateStream~TResponse~(IContextAware contextAware, IStreamRequest~TResponse~ request, CancellationToken cancellationToken)
+ValueTask SendAsync~TCommand~(IContextAware contextAware, TCommand command, CancellationToken cancellationToken)
+ValueTask~TResponse~ SendAsync~TResponse~(IContextAware contextAware, IRequest~TResponse~ command, CancellationToken cancellationToken)
}
class ContextAwareCommandExtensions {
<<static>>
+TResponse SendCommand~TResponse~(IContextAware contextAware, Mediator_ICommand~TResponse~ command)
+TResult SendCommand~TResult~(IContextAware contextAware, ICommand~TResult~ command)
+void SendCommand(IContextAware contextAware, ICommand command)
+ValueTask~TResponse~ SendCommandAsync~TResponse~(IContextAware contextAware, Mediator_ICommand~TResponse~ command, CancellationToken cancellationToken)
+Task SendCommandAsync(IContextAware contextAware, IAsyncCommand command)
+Task~TResult~ SendCommandAsync~TResult~(IContextAware contextAware, IAsyncCommand~TResult~ command)
}
class ContextAwareQueryExtensions {
<<static>>
+TResponse SendQuery~TResponse~(IContextAware contextAware, Mediator_IQuery~TResponse~ query)
+TResult SendQuery~TResult~(IContextAware contextAware, IQuery~TResult~ query)
+ValueTask~TResponse~ SendQueryAsync~TResponse~(IContextAware contextAware, Mediator_IQuery~TResponse~ query, CancellationToken cancellationToken)
+Task~TResult~ SendQueryAsync~TResult~(IContextAware contextAware, IAsyncQuery~TResult~ query)
}
class IArchitectureContext
class IEnvironment
class IEventBus {
+void Publish~TEvent~(TEvent e)
+IUnRegister Register~TEvent~(Action~TEvent~ handler)
+void UnRegister~TEvent~(Action~TEvent~ handler)
}
class EventBus {
+void Publish~TEvent~(TEvent e)
+IUnRegister Register~TEvent~(Action~TEvent~ handler)
+void UnRegister~TEvent~(Action~TEvent~ handler)
}
class IUnRegister {
+void UnRegister()
}
class IRequest~TResponse~
class IStreamRequest~TResponse~
class Mediator_ICommand~TResponse~
class Mediator_IQuery~TResponse~
class ICommand
class ICommand~TResult~
class IAsyncCommand
class IAsyncCommand~TResult~
class IQuery~TResult~
class IAsyncQuery~TResult~
ContextAwareServiceExtensions ..> IContextAware
ContextAwareServiceExtensions ..> IArchitectureContext
ContextAwareEnvironmentExtensions ..> IContextAware
ContextAwareEnvironmentExtensions ..> IArchitectureContext
ContextAwareEnvironmentExtensions ..> IEnvironment
ContextAwareEventExtensions ..> IContextAware
ContextAwareEventExtensions ..> IArchitectureContext
ContextAwareEventExtensions ..> IUnRegister
ContextAwareMediatorExtensions ..> IContextAware
ContextAwareMediatorExtensions ..> IArchitectureContext
ContextAwareCommandExtensions ..> IContextAware
ContextAwareCommandExtensions ..> IArchitectureContext
ContextAwareQueryExtensions ..> IContextAware
ContextAwareQueryExtensions ..> IArchitectureContext
EventBus ..|> IEventBus
ContextAwareBase o-- IArchitectureContext
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 4, 2026 3:05p.m. | Review ↗ | |
| Secrets | Mar 4, 2026 3:05p.m. | Review ↗ |
There was a problem hiding this comment.
Hey - 我在这里给出了一些总体反馈:
- 在同一个扩展类中同时使用 Mediator.ICommand/IQuery 和你自己的 Abstractions.command.ICommand/Abstractions.query.IQuery 有些让人困惑;可以考虑添加 using 别名,或者将 Mediator 专用的扩展拆分到单独的文件中,以便让调用位置和后续维护更清晰。
- 在新的 ContextAware*Extensions 方法中,你多次通过
var context = contextAware.GetContext();获取上下文;你可以把这一逻辑提取到一个私有的小辅助方法中(例如GetRequiredContext(this IContextAware)),以减少重复,并且明确GetContext()是否预期为非空。
给 AI Agents 的提示
Please address the comments from this code review:
## Overall Comments
- The coexistence of Mediator.ICommand/IQuery and your own Abstractions.command.ICommand/Abstractions.query.IQuery in the same extension classes is a bit confusing; consider adding using-aliases or splitting Mediator-specific extensions into separate files to make call sites and future maintenance clearer.
- In the new ContextAware*Extensions methods you repeatedly fetch the context via `var context = contextAware.GetContext();`; you could factor this into a small private helper (e.g. `GetRequiredContext(this IContextAware)`) to reduce duplication and make it explicit if `GetContext()` is expected to be non-null.帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进之后的代码评审。
Original comment in English
Hey - I've left some high level feedback:
- The coexistence of Mediator.ICommand/IQuery and your own Abstractions.command.ICommand/Abstractions.query.IQuery in the same extension classes is a bit confusing; consider adding using-aliases or splitting Mediator-specific extensions into separate files to make call sites and future maintenance clearer.
- In the new ContextAware*Extensions methods you repeatedly fetch the context via
var context = contextAware.GetContext();; you could factor this into a small private helper (e.g.GetRequiredContext(this IContextAware)) to reduce duplication and make it explicit ifGetContext()is expected to be non-null.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The coexistence of Mediator.ICommand/IQuery and your own Abstractions.command.ICommand/Abstractions.query.IQuery in the same extension classes is a bit confusing; consider adding using-aliases or splitting Mediator-specific extensions into separate files to make call sites and future maintenance clearer.
- In the new ContextAware*Extensions methods you repeatedly fetch the context via `var context = contextAware.GetContext();`; you could factor this into a small private helper (e.g. `GetRequiredContext(this IContextAware)`) to reduce duplication and make it explicit if `GetContext()` is expected to be non-null.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 将原有的 ContextAwareCommandExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorCommandExtensions 类中 - 将原有的 ContextAwareQueryExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorQueryExtensions 类中 - 移除 ContextAwareCommandExtensions 中的异步命令方法 SendCommandAsync - 移除 ContextAwareQueryExtensions 中的异步查询方法 SendQueryAsync - 修复了 ContextAwareCommandExtensions 中的泛型类型参数引用问题 - 统一了代码格式和命名空间引用 - 保持了原有功能的向后兼容性
This was referenced Mar 7, 2026
This was referenced Mar 15, 2026
This was referenced May 10, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary by Sourcery
扩展架构上下文和上下文感知 API,以支持批量组件检索,并为服务、环境、事件、命令、查询和中介请求提供更细粒度的扩展点。
新特性:
测试:
Original summary in English
Summary by Sourcery
Extend architecture context and context-aware APIs to support bulk component retrieval and more granular extension points for services, environment, events, commands, queries, and mediator requests.
New Features:
Tests: