#nullable enable using System.Collections.Generic; using Cysharp.Threading.Tasks; using ShrinkContext; namespace ShrinkDataSaver.Integration { /// 注入 DataSaver 服务键并把其原生事件显式接到 EventBus。 public sealed class ShrinkDataSaverEventBusComponent : IShrinkComponent { public const string DataSaverServiceKey = "shrink.service.datasaver"; public const string ProvideKey = "shrink.integration.datasaver-eventbus"; private static readonly string[] InjectKeys = { DataSaverServiceKey }; private static readonly string[] ProvideKeys = { ProvideKey }; public string Name => "shrink.integration.datasaver-eventbus"; public IReadOnlyList Inject => InjectKeys; public IReadOnlyList Provide => ProvideKeys; public UniTask ApplyAsync(ShrinkCtx ctx, object? config) { _ = ctx.Get(DataSaverServiceKey); DataSaverEventBusBridge.Register(); ctx.EffectInverse(() => { DataSaverEventBusBridge.Unregister(); return UniTask.CompletedTask; }); ctx.Set(ProvideKey, Name); return UniTask.CompletedTask; } } }