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);
|
||||
}
|
||||
@@ -37,6 +37,8 @@ public class Startup
|
||||
private PluginLoaderService PluginLoaderService;
|
||||
private ApplicationAssemblyService ApplicationAssemblyService;
|
||||
|
||||
private IAppStartup[] PluginAppStartups;
|
||||
|
||||
public async Task Run(string[] args, Assembly[]? assemblies = null)
|
||||
{
|
||||
Args = args;
|
||||
@@ -53,15 +55,18 @@ public class Startup
|
||||
await CreateWebAssemblyHostBuilder();
|
||||
|
||||
await LoadPlugins();
|
||||
await InitializePlugins();
|
||||
|
||||
await RegisterLogging();
|
||||
await RegisterBase();
|
||||
await RegisterOAuth2();
|
||||
await RegisterFormComponents();
|
||||
await RegisterInterfaces();
|
||||
await HookPluginBuild();
|
||||
|
||||
await BuildWebAssemblyHost();
|
||||
|
||||
await HookPluginConfigure();
|
||||
await LoadAssets();
|
||||
|
||||
await WebAssemblyHost.RunAsync();
|
||||
@@ -185,6 +190,72 @@ public class Startup
|
||||
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
|
||||
|
||||
#region Logging
|
||||
|
||||
Reference in New Issue
Block a user