32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using ShrinkApp;
|
|
|
|
namespace ShrinkContext.AppAdapter;
|
|
|
|
public sealed class ShrinkContextAppHost
|
|
{
|
|
private readonly ShrinkContextRuntime _runtime = new();
|
|
private readonly ShrinkComponentCatalog _catalog = new();
|
|
private readonly ShrinkContextLoader _loader;
|
|
|
|
public ShrinkContextAppHost(ShrinkAppServices? services = null)
|
|
{
|
|
Services = services ?? new ShrinkAppServices();
|
|
_loader = new ShrinkContextLoader(_runtime, _catalog);
|
|
}
|
|
|
|
public ShrinkAppServices Services { get; }
|
|
public ShrinkContextRuntime Runtime => _runtime;
|
|
public ShrinkLoaderTransactionDiagnostic? LastTransaction => _loader.LastTransaction;
|
|
|
|
public void Register(string name, Func<IShrinkComponent> factory) => _catalog.Register(name, factory);
|
|
public void Register<TComponent>(string name) where TComponent : IShrinkComponent, new() =>
|
|
_catalog.Register<TComponent>(name);
|
|
public UniTask ApplyAsync(IReadOnlyList<ShrinkLoaderEntry> entries) => _loader.ApplyAsync(entries);
|
|
public UniTask ShutdownAsync() => _runtime.ShutdownAsync();
|
|
}
|