#nullable enable using System; using System.Collections.Generic; using Cysharp.Threading.Tasks; using ShrinkCommand; using ShrinkContext; using ShrinkNetwork; namespace ShrinkCommand.Integration { /// /// 命令-网络集成组件(论文 6.5 集成组件模式): /// 核心(command / network)互不依赖,本组件注入双方服务键,全部就绪才激活, /// 任一提供者退役即自动停用——依赖接线由响应式余效应结构性完成,替代手工桥接编排。 /// /// 已知边界:ShrinkNetworkService 当前无 handler 注销 API,停用不撤销已注册的 /// command/execute 处理器(传输解绑后不可达;网络服务实例重建时自然消失)。 /// public sealed class ShrinkCommandNetworkIntegrationComponent : IShrinkComponent { /// 与 ShrinkNetworkAppComponent.ServiceKey 保持一致(避免跨包硬引用)。 public const string NetworkServiceKey = "shrink.service.network"; public const string CommandServiceKey = "shrink.service.command"; public const string ProvideKey = "shrink.integration.command-network"; private static readonly string[] InjectKeys = { CommandServiceKey, NetworkServiceKey }; private static readonly string[] ProvideKeys = { ProvideKey }; public string Name => "shrink.integration.command-network"; public IReadOnlyList Inject => InjectKeys; public IReadOnlyList Provide => ProvideKeys; public UniTask ApplyAsync(ShrinkCtx ctx, object? config) { var commandService = ctx.Get(CommandServiceKey); var networkService = ctx.Get(NetworkServiceKey); var options = config as ShrinkNetworkCommandBridgeOptions; ShrinkNetworkCommandBridge.RegisterService(networkService, commandService, options); ctx.Set(ProvideKey, ShrinkNetworkCommandBridge.ExecuteRoute); // 桥注册按网络服务实例幂等去重;可逆面为集成键的发布/撤回 return UniTask.CompletedTask; } } }