Improved handling of moonlight plugins during startup, minimized host project code and moved startup handling to core
This commit is contained in:
42
Moonlight.Api/StartupHandler.cs
Normal file
42
Moonlight.Api/StartupHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Moonlight.Api;
|
||||
|
||||
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 = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Setting up context
|
||||
foreach (var plugin in plugins)
|
||||
plugin.Initialize(plugins);
|
||||
|
||||
// Stage 1: Pre Build
|
||||
foreach (var startup in plugins)
|
||||
startup.PreBuild(builder);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Stage 2: Post Build
|
||||
foreach (var startup in plugins)
|
||||
startup.PostBuild(app);
|
||||
|
||||
// Stage 3: Post Middleware
|
||||
foreach (var startup in plugins)
|
||||
startup.PostMiddleware(app);
|
||||
|
||||
// Frontend debugging
|
||||
if (app.Environment.IsDevelopment())
|
||||
app.UseWebAssemblyDebugging();
|
||||
|
||||
// Frontend hosting
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user