This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkContext;
|
||||
|
||||
namespace ShrinkDataSaver.Integration
|
||||
{
|
||||
/// <summary>注入 DataSaver 服务键并把其原生事件显式接到 EventBus。</summary>
|
||||
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<string> Inject => InjectKeys;
|
||||
public IReadOnlyList<string> Provide => ProvideKeys;
|
||||
|
||||
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
|
||||
{
|
||||
_ = ctx.Get<object>(DataSaverServiceKey);
|
||||
DataSaverEventBusBridge.Register();
|
||||
ctx.EffectInverse(() =>
|
||||
{
|
||||
DataSaverEventBusBridge.Unregister();
|
||||
return UniTask.CompletedTask;
|
||||
});
|
||||
ctx.Set(ProvideKey, Name);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user