Improved handling of moonlight plugins during startup, minimized host project code and moved startup handling to core
This commit is contained in:
10
Moonlight.Frontend/MoonlightPlugin.cs
Normal file
10
Moonlight.Frontend/MoonlightPlugin.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using SimplePlugin.Abstractions;
|
||||
|
||||
namespace Moonlight.Frontend;
|
||||
|
||||
public abstract class MoonlightPlugin : IPluginModule
|
||||
{
|
||||
public virtual void PreBuild(WebAssemblyHostBuilder builder){}
|
||||
public virtual void PostBuild(WebAssemblyHost application){}
|
||||
}
|
||||
@@ -4,15 +4,15 @@ using SimplePlugin.Abstractions;
|
||||
namespace Moonlight.Frontend.Startup;
|
||||
|
||||
[PluginModule]
|
||||
public partial class Startup : IAppStartup
|
||||
public partial class Startup : MoonlightPlugin
|
||||
{
|
||||
public void PreBuild(WebAssemblyHostBuilder builder)
|
||||
public override void PreBuild(WebAssemblyHostBuilder builder)
|
||||
{
|
||||
AddBase(builder);
|
||||
AddAuth(builder);
|
||||
}
|
||||
|
||||
public void PostBuild(WebAssemblyHost application)
|
||||
public override void PostBuild(WebAssemblyHost application)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
23
Moonlight.Frontend/StartupHandler.cs
Normal file
23
Moonlight.Frontend/StartupHandler.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
|
||||
namespace Moonlight.Frontend;
|
||||
|
||||
public static class StartupHandler
|
||||
{
|
||||
public static async Task RunAsync(string[] args, MoonlightPlugin[] plugins)
|
||||
{
|
||||
Console.WriteLine($"Starting with: {string.Join(", ", plugins.Select(x => x.GetType().FullName))}");
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
foreach (var plugin in plugins)
|
||||
plugin.PreBuild(builder);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
foreach(var plugin in plugins)
|
||||
plugin.PostBuild(app);
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user