diff --git a/Moonlight/App/Plugins/Contexts/PluginContext.cs b/Moonlight/App/Plugins/Contexts/PluginContext.cs index 99572ab2..90ba8324 100644 --- a/Moonlight/App/Plugins/Contexts/PluginContext.cs +++ b/Moonlight/App/Plugins/Contexts/PluginContext.cs @@ -5,6 +5,8 @@ public class PluginContext public IServiceCollection Services { get; set; } public IServiceProvider Provider { get; set; } public IServiceScope Scope { get; set; } + public WebApplicationBuilder WebApplicationBuilder { get; set; } + public WebApplication WebApplication { get; set; } public List PreInitTasks = new(); public List PostInitTasks = new(); } \ No newline at end of file diff --git a/Moonlight/App/Services/PluginService.cs b/Moonlight/App/Services/PluginService.cs index bc32d9e9..81a3712d 100644 --- a/Moonlight/App/Services/PluginService.cs +++ b/Moonlight/App/Services/PluginService.cs @@ -9,7 +9,7 @@ public class PluginService { private readonly List Plugins = new(); - public async Task Load(IServiceCollection services) + public async Task Load(WebApplicationBuilder webApplicationBuilder) { var path = PathBuilder.Dir("storage", "plugins"); Directory.CreateDirectory(path); @@ -36,7 +36,8 @@ public class PluginService // Create environment plugin.Context = new PluginContext() { - Services = services + Services = webApplicationBuilder.Services, + WebApplicationBuilder = webApplicationBuilder }; try @@ -87,14 +88,15 @@ public class PluginService } } - public async Task RunPrePost(IServiceProvider provider) + public async Task RunPrePost(WebApplication webApplication) { foreach (var plugin in Plugins) { // Pass through the dependency injection - var scope = provider.CreateScope(); + var scope = webApplication.Services.CreateScope(); plugin.Context.Provider = scope.ServiceProvider; plugin.Context.Scope = scope; + plugin.Context.WebApplication = webApplication; Logger.Info($"Running post init tasks for {plugin.GetType().Name}"); diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index ee5e3d04..fe9ebe16 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -33,7 +33,7 @@ var builder = WebApplication.CreateBuilder(args); var pluginService = new PluginService(); builder.Services.AddSingleton(pluginService); -await pluginService.Load(builder.Services); +await pluginService.Load(builder); await pluginService.RunPreInit(); builder.Services.AddDbContext(); @@ -106,6 +106,6 @@ app.Services.GetRequiredService(); var serviceService = app.Services.GetRequiredService(); await serviceService.RegisterAction(ServiceType.Server, new DummyActions()); -await pluginService.RunPrePost(app.Services); +await pluginService.RunPrePost(app); app.Run(); \ No newline at end of file