feat(cordis): 接入上下文组合与模组事务热替换
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkContext;
|
||||
|
||||
namespace ShrinkNetwork.Integration
|
||||
{
|
||||
/// <summary>通过网络服务键管理 Network ↔ EventBus 桥的可逆生命周期。</summary>
|
||||
public sealed class ShrinkNetworkEventBusComponent : IShrinkComponent
|
||||
{
|
||||
public const string NetworkServiceKey = "shrink.service.network";
|
||||
public const string ProvideKey = "shrink.integration.network-eventbus";
|
||||
|
||||
private static readonly string[] InjectKeys = { NetworkServiceKey };
|
||||
private static readonly string[] ProvideKeys = { ProvideKey };
|
||||
|
||||
public string Name => "shrink.integration.network-eventbus";
|
||||
public IReadOnlyList<string> Inject => InjectKeys;
|
||||
public IReadOnlyList<string> Provide => ProvideKeys;
|
||||
|
||||
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
|
||||
{
|
||||
var service = ctx.Get<ShrinkNetworkService>(NetworkServiceKey);
|
||||
service.UseEventBusBridge(config as ShrinkNetworkEventBusBridgeOptions);
|
||||
ctx.EffectInverse(() =>
|
||||
{
|
||||
ShrinkNetworkEventBusBridge.UnregisterService(service);
|
||||
return UniTask.CompletedTask;
|
||||
});
|
||||
ctx.Set(ProvideKey, Name);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user