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