This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShrinkCommand.Integration.App;
|
||||
using ShrinkCommand.Integration;
|
||||
using ShrinkContext.AppAdapter;
|
||||
using ShrinkDataSaver.Integration.App;
|
||||
using ShrinkDataSaver.Integration;
|
||||
using ShrinkNetwork.Integration.App;
|
||||
using ShrinkNetwork.Integration;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShrinkApp.Starter.Basic
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic Starter 的组合根:ContextLoader 模式下默认使用原生 Cordis 组件,
|
||||
/// 不再把三个功能模块交给 IShrinkAppModuleInstaller 包装器执行。
|
||||
/// </summary>
|
||||
public static class ShrinkAppBasicContextComposition
|
||||
{
|
||||
private static readonly string[] DefaultModuleIdValues =
|
||||
{
|
||||
"shrink.network",
|
||||
"shrink.command",
|
||||
"shrink.datasaver",
|
||||
"shrink.integration.command-network",
|
||||
"shrink.integration.command-eventbus",
|
||||
"shrink.integration.datasaver-eventbus",
|
||||
"shrink.integration.network-eventbus"
|
||||
};
|
||||
|
||||
public static IReadOnlyList<string> DefaultModuleIds => DefaultModuleIdValues;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void RegisterDefaultComposition()
|
||||
{
|
||||
ShrinkAppLoaderBootstrapper.DefaultComposition = Configure;
|
||||
}
|
||||
|
||||
public static void Configure(ShrinkAppLoaderHost host)
|
||||
{
|
||||
if (host == null)
|
||||
throw new System.ArgumentNullException(nameof(host));
|
||||
|
||||
RegisterOrReplace(host, "shrink.network", static () => new ShrinkNetworkAppComponent());
|
||||
RegisterOrReplace(host, "shrink.command", static () => new ShrinkCommandAppComponent());
|
||||
RegisterOrReplace(host, "shrink.datasaver", static () => new ShrinkDataSaverAppComponent());
|
||||
host.AddModuleComponent("shrink.integration.command-network",
|
||||
static () => new ShrinkCommandNetworkIntegrationComponent());
|
||||
host.AddModuleComponent("shrink.integration.command-eventbus",
|
||||
static () => new ShrinkCommandEventBusComponent());
|
||||
host.AddModuleComponent("shrink.integration.datasaver-eventbus",
|
||||
static () => new ShrinkDataSaverEventBusComponent());
|
||||
host.AddModuleComponent("shrink.integration.network-eventbus",
|
||||
static () => new ShrinkNetworkEventBusComponent());
|
||||
}
|
||||
|
||||
private static void RegisterOrReplace(
|
||||
ShrinkAppLoaderHost host,
|
||||
string moduleId,
|
||||
System.Func<ShrinkContext.IShrinkComponent> componentFactory)
|
||||
{
|
||||
if (host.ModuleIds.Any(id => string.Equals(id, moduleId, System.StringComparison.OrdinalIgnoreCase)))
|
||||
host.OverrideModuleComponent(moduleId, componentFactory);
|
||||
else
|
||||
host.AddModuleComponent(moduleId, componentFactory);
|
||||
}
|
||||
|
||||
public static ShrinkAppCompositionDocument CreateDefaultDocument()
|
||||
{
|
||||
var entries = new List<ShrinkAppCompositionEntry>(DefaultModuleIdValues.Length);
|
||||
foreach (var moduleId in DefaultModuleIdValues)
|
||||
entries.Add(new ShrinkAppCompositionEntry(moduleId));
|
||||
return new ShrinkAppCompositionDocument(includeUnlistedEntries: false, entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user