This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "ShrinkCommand.Integration.App",
|
||||
"rootNamespace": "ShrinkCommand.Integration.App",
|
||||
"references": [
|
||||
"ShrinkCommand.Runtime",
|
||||
"ShrinkApp.Core.Runtime",
|
||||
"ShrinkContext.Core.Runtime",
|
||||
"UniTask"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5805c0a2f81e6f47818b1dac7d15e6c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkApp;
|
||||
using ShrinkContext;
|
||||
using ShrinkCommand;
|
||||
|
||||
namespace ShrinkCommand.Integration.App
|
||||
{
|
||||
/// <summary>
|
||||
/// ShrinkCommand 的原生 Cordis 组件(阶段 3):
|
||||
/// 提供 <c>shrink.service.command</c> 余效应键(默认命令服务),依赖者按键注入;
|
||||
/// 与经典 ShrinkCommandAppInstaller(ModuleId "shrink.command")二选一使用(同键供给冲突保护)。
|
||||
/// </summary>
|
||||
public sealed class ShrinkCommandAppComponent : IShrinkComponent
|
||||
{
|
||||
public const string ServiceKey = "shrink.service.command";
|
||||
public const string ModuleKey = "app.module.shrink.command";
|
||||
|
||||
private static readonly string[] ProvideKeys = { ModuleKey, ServiceKey };
|
||||
|
||||
public string Name => "shrink.command";
|
||||
|
||||
public IReadOnlyList<string> Inject => Array.Empty<string>();
|
||||
|
||||
public IReadOnlyList<string> Provide => ProvideKeys;
|
||||
|
||||
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
|
||||
{
|
||||
var service = ShrinkCommandRuntime.Default;
|
||||
ctx.Set(ServiceKey, service);
|
||||
ctx.Set(ModuleKey, Name);
|
||||
|
||||
if (config is ShrinkAppServices appServices)
|
||||
{
|
||||
var facade = new ShrinkCommandAppService(service);
|
||||
appServices.Register(facade);
|
||||
ctx.EffectInverse(() =>
|
||||
{
|
||||
appServices.TryUnregister(facade);
|
||||
return UniTask.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 507e23e02986281488456a63dc8ffdbe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkApp;
|
||||
|
||||
namespace ShrinkCommand.Integration.App
|
||||
{
|
||||
[ShrinkAppModuleInstaller]
|
||||
[Obsolete("ClassicHost compatibility only. ContextLoader projects should use ShrinkCommandAppComponent from a composition root.")]
|
||||
public sealed class ShrinkCommandAppInstaller : IShrinkAppModuleInstaller
|
||||
{
|
||||
public string ModuleId => "shrink.command";
|
||||
public int Order => -1500;
|
||||
public System.Collections.Generic.IReadOnlyList<string> DependsOn => Array.Empty<string>();
|
||||
|
||||
public void RegisterServices(ShrinkAppContext context)
|
||||
{
|
||||
context.Services.Register(new ShrinkCommandAppService(ShrinkCommandRuntime.Default));
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync(ShrinkAppContext context)
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ShrinkCommandAppService
|
||||
{
|
||||
public ShrinkCommandAppService(ShrinkCommandService service)
|
||||
{
|
||||
Service = service ?? throw new ArgumentNullException(nameof(service));
|
||||
}
|
||||
|
||||
public ShrinkCommandService Service { get; }
|
||||
|
||||
public UniTask<ShrinkCommandExecutionResult> ExecuteAsync(
|
||||
IShrinkCommandSource source,
|
||||
string rawInput,
|
||||
System.Threading.CancellationToken cancellationToken = default)
|
||||
=> Service.ExecuteAsync(source, rawInput, cancellationToken);
|
||||
|
||||
public string BuildHelp(IShrinkCommandSource? source, string? prefix = null)
|
||||
=> Service.BuildHelp(source, prefix);
|
||||
|
||||
public System.Collections.Generic.IReadOnlyList<ShrinkCommandDescriptor> Commands => Service.Commands;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a71473a2ecd04c3459903841fee6da7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user