You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Instance/Instance.cs

64 lines
1.6 KiB

using Connected.Interop;
using Microsoft.AspNetCore.Builder;
namespace Connected.Instance
{
public static class Instance
{
internal static WebApplication Host { get; private set; }
internal static async Task StartAsync(Dictionary<string, string> args)
{
var builder = WebApplication.CreateBuilder(UnpackArguments(args));
var startups = Assemblies.QueryImplementations<IStartup>();
foreach (var assembly in Assemblies.All)
builder.Services.AddMicroService(assembly);
foreach (var startup in startups)
{
if (startup.CreateInstance<IStartup>() is IStartup start)
start.ConfigureServices(builder.Services);
}
Host = builder.Build();
foreach (var startup in startups)
{
if (startup.CreateInstance<IStartup>() is IStartup start)
start.Configure(Host);
}
foreach (var startup in startups)
{
if (startup.CreateInstance<IStartup>() is IStartup start)
await start.Initialize(args);
}
foreach (var startup in startups)
{
if (startup.CreateInstance<IStartup>() is IStartup start)
await start.Start(args);
}
if (args.TryGetValue("entitySynchronization", out string? entities))
await EntitySynchronizer.Synchronize(Host.Services, entities);
await Host.RunAsync();
}
private static string[] UnpackArguments(Dictionary<string, string> args)
{
var result = new string[args.Count];
for (var i = 0; i < args.Count; i++)
{
var arg = args.ElementAt(i);
result[i] = string.IsNullOrWhiteSpace(arg.Value) ? arg.Key : $"{arg.Key}={arg.Value}";
}
return result;
}
}
}