This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user