Added app startup for the frontend
This commit is contained in:
9
Moonlight.Client/Interfaces/IAppStartup.cs
Normal file
9
Moonlight.Client/Interfaces/IAppStartup.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
|
|
||||||
|
namespace Moonlight.Client.Interfaces;
|
||||||
|
|
||||||
|
public interface IAppStartup
|
||||||
|
{
|
||||||
|
public Task BuildApp(WebAssemblyHostBuilder builder);
|
||||||
|
public Task ConfigureApp(WebAssemblyHost app);
|
||||||
|
}
|
||||||
@@ -36,6 +36,8 @@ public class Startup
|
|||||||
// Plugin Loading
|
// Plugin Loading
|
||||||
private PluginLoaderService PluginLoaderService;
|
private PluginLoaderService PluginLoaderService;
|
||||||
private ApplicationAssemblyService ApplicationAssemblyService;
|
private ApplicationAssemblyService ApplicationAssemblyService;
|
||||||
|
|
||||||
|
private IAppStartup[] PluginAppStartups;
|
||||||
|
|
||||||
public async Task Run(string[] args, Assembly[]? assemblies = null)
|
public async Task Run(string[] args, Assembly[]? assemblies = null)
|
||||||
{
|
{
|
||||||
@@ -53,15 +55,18 @@ public class Startup
|
|||||||
await CreateWebAssemblyHostBuilder();
|
await CreateWebAssemblyHostBuilder();
|
||||||
|
|
||||||
await LoadPlugins();
|
await LoadPlugins();
|
||||||
|
await InitializePlugins();
|
||||||
|
|
||||||
await RegisterLogging();
|
await RegisterLogging();
|
||||||
await RegisterBase();
|
await RegisterBase();
|
||||||
await RegisterOAuth2();
|
await RegisterOAuth2();
|
||||||
await RegisterFormComponents();
|
await RegisterFormComponents();
|
||||||
await RegisterInterfaces();
|
await RegisterInterfaces();
|
||||||
|
await HookPluginBuild();
|
||||||
|
|
||||||
await BuildWebAssemblyHost();
|
await BuildWebAssemblyHost();
|
||||||
|
|
||||||
|
await HookPluginConfigure();
|
||||||
await LoadAssets();
|
await LoadAssets();
|
||||||
|
|
||||||
await WebAssemblyHost.RunAsync();
|
await WebAssemblyHost.RunAsync();
|
||||||
@@ -185,6 +190,72 @@ public class Startup
|
|||||||
WebAssemblyHostBuilder.Services.AddSingleton(ApplicationAssemblyService);
|
WebAssemblyHostBuilder.Services.AddSingleton(ApplicationAssemblyService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task InitializePlugins()
|
||||||
|
{
|
||||||
|
var initialisationServiceCollection = new ServiceCollection();
|
||||||
|
|
||||||
|
initialisationServiceCollection.AddLogging(builder => { builder.AddProviders(LoggerProviders); });
|
||||||
|
|
||||||
|
// Configure plugin loading by using the interface service
|
||||||
|
initialisationServiceCollection.AddInterfaces(configuration =>
|
||||||
|
{
|
||||||
|
// We use moonlight itself as a plugin assembly
|
||||||
|
configuration.AddAssembly(typeof(Startup).Assembly);
|
||||||
|
|
||||||
|
configuration.AddAssemblies(PluginLoaderService.PluginAssemblies);
|
||||||
|
|
||||||
|
configuration.AddInterface<IAppStartup>();
|
||||||
|
});
|
||||||
|
|
||||||
|
var initialisationServiceProvider = initialisationServiceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
|
PluginAppStartups = initialisationServiceProvider.GetRequiredService<IAppStartup[]>();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Hooks
|
||||||
|
|
||||||
|
private async Task HookPluginBuild()
|
||||||
|
{
|
||||||
|
foreach (var pluginAppStartup in PluginAppStartups)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await pluginAppStartup.BuildApp(WebAssemblyHostBuilder);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(
|
||||||
|
"An error occured while processing 'BuildApp' for '{name}': {e}",
|
||||||
|
pluginAppStartup.GetType().FullName,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HookPluginConfigure()
|
||||||
|
{
|
||||||
|
foreach (var pluginAppStartup in PluginAppStartups)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await pluginAppStartup.ConfigureApp(WebAssemblyHost);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(
|
||||||
|
"An error occured while processing 'ConfigureApp' for '{name}': {e}",
|
||||||
|
pluginAppStartup.GetType().FullName,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Logging
|
#region Logging
|
||||||
|
|||||||
Reference in New Issue
Block a user