Files
ShrinkCommand.Integration.E…/ShrinkCommandEventBusComponent.cs
cneicy 06157bf15c
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:49:45 +08:00

37 lines
1.4 KiB
C#

#nullable enable
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkContext;
namespace ShrinkCommand.Integration
{
/// <summary>通过命令服务键管理 Command ↔ EventBus 桥的可逆生命周期。</summary>
public sealed class ShrinkCommandEventBusComponent : IShrinkComponent
{
public const string CommandServiceKey = "shrink.service.command";
public const string ProvideKey = "shrink.integration.command-eventbus";
private static readonly string[] InjectKeys = { CommandServiceKey };
private static readonly string[] ProvideKeys = { ProvideKey };
public string Name => "shrink.integration.command-eventbus";
public IReadOnlyList<string> Inject => InjectKeys;
public IReadOnlyList<string> Provide => ProvideKeys;
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
{
var service = ctx.Get<ShrinkCommandService>(CommandServiceKey);
var options = config as ShrinkCommandEventBusBridgeOptions;
ShrinkCommandEventBusBridge.RegisterService(service, options);
ctx.EffectInverse(() =>
{
ShrinkCommandEventBusBridge.UnregisterService(service);
return UniTask.CompletedTask;
});
ctx.Set(ProvideKey, Name);
return UniTask.CompletedTask;
}
}
}