#nullable enable using System.Collections.Generic; using Cysharp.Threading.Tasks; using ShrinkContext; namespace ShrinkNetwork.Integration { /// 通过网络服务键管理 Network ↔ EventBus 桥的可逆生命周期。 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 Inject => InjectKeys; public IReadOnlyList Provide => ProvideKeys; public UniTask ApplyAsync(ShrinkCtx ctx, object? config) { var service = ctx.Get(NetworkServiceKey); service.UseEventBusBridge(config as ShrinkNetworkEventBusBridgeOptions); ctx.EffectInverse(() => { ShrinkNetworkEventBusBridge.UnregisterService(service); return UniTask.CompletedTask; }); ctx.Set(ProvideKey, Name); return UniTask.CompletedTask; } } }