Implemented plugin loading via di on the api server. Fixed plugin loading in the client
This commit is contained in:
17
Moonlight.Client/Implementations/CoreStartup.cs
Normal file
17
Moonlight.Client/Implementations/CoreStartup.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using Moonlight.Client.Interfaces;
|
||||
|
||||
namespace Moonlight.Client.Implementations;
|
||||
|
||||
public class CoreStartup : IPluginStartup
|
||||
{
|
||||
public Task BuildApplication(WebAssemblyHostBuilder builder)
|
||||
{
|
||||
builder.Services.AddSingleton<ISidebarItemProvider, DefaultSidebarItemProvider>();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task ConfigureApplication(WebAssemblyHost app)
|
||||
=> Task.CompletedTask;
|
||||
}
|
||||
@@ -24,10 +24,10 @@
|
||||
<PackageReference Include="Blazor-ApexCharts" Version="4.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.10"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.10" PrivateAssets="all"/>
|
||||
<PackageReference Include="MoonCore" Version="1.8.2" />
|
||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.8" />
|
||||
<PackageReference Include="MoonCore" Version="1.8.3" />
|
||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.9" />
|
||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.5"/>
|
||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.3.0" />
|
||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.3.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -8,13 +8,12 @@ using MoonCore.Blazor.Tailwind.Extensions;
|
||||
using MoonCore.Blazor.Tailwind.Auth;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using MoonCore.Plugins;
|
||||
using Moonlight.Client.Implementations;
|
||||
using Moonlight.Client.Interfaces;
|
||||
using Moonlight.Client.Services;
|
||||
using Moonlight.Client.UI;
|
||||
using Moonlight.Shared.Misc;
|
||||
using Moonlight.Client.UI;
|
||||
|
||||
namespace Moonlight.Client;
|
||||
|
||||
@@ -62,7 +61,6 @@ public class Startup
|
||||
await RegisterLogging();
|
||||
await RegisterBase();
|
||||
await RegisterAuthentication();
|
||||
await RegisterInterfaces();
|
||||
await HookPluginBuild();
|
||||
|
||||
await BuildWebAssemblyHost();
|
||||
@@ -153,7 +151,9 @@ public class Startup
|
||||
WebAssemblyHostBuilder.Services.AddMoonCoreBlazorTailwind();
|
||||
WebAssemblyHostBuilder.Services.AddScoped<LocalStorageService>();
|
||||
|
||||
WebAssemblyHostBuilder.Services.AutoAddServices<Program>();
|
||||
WebAssemblyHostBuilder.Services.AddScoped<ThemeService>();
|
||||
|
||||
//WebAssemblyHostBuilder.Services.AutoAddServices<Program>();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -170,26 +170,6 @@ public class Startup
|
||||
|
||||
#endregion
|
||||
|
||||
#region Interfaces
|
||||
|
||||
private Task RegisterInterfaces()
|
||||
{
|
||||
WebAssemblyHostBuilder.Services.AddInterfaces(configuration =>
|
||||
{
|
||||
// We use moonlight itself as a plugin assembly
|
||||
configuration.AddAssembly(typeof(Startup).Assembly);
|
||||
|
||||
configuration.AddAssemblies(ApplicationAssemblyService.AdditionalAssemblies);
|
||||
configuration.AddAssemblies(ApplicationAssemblyService.PluginAssemblies);
|
||||
|
||||
configuration.AddInterface<ISidebarItemProvider>();
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Plugins
|
||||
|
||||
private async Task LoadPlugins()
|
||||
@@ -240,12 +220,18 @@ public class Startup
|
||||
// Initialize plugin startups
|
||||
var startups = new List<IPluginStartup>();
|
||||
var startupType = typeof(IPluginStartup);
|
||||
|
||||
var assembliesToScan = new List<Assembly>();
|
||||
|
||||
assembliesToScan.Add(typeof(Startup).Assembly);
|
||||
assembliesToScan.AddRange(PluginLoaderService.PluginAssemblies);
|
||||
assembliesToScan.AddRange(ApplicationAssemblyService.AdditionalAssemblies);
|
||||
|
||||
foreach (var pluginAssembly in ApplicationAssemblyService.PluginAssemblies)
|
||||
foreach (var pluginAssembly in assembliesToScan)
|
||||
{
|
||||
var startupTypes = pluginAssembly
|
||||
.ExportedTypes
|
||||
.Where(x => x.IsAbstract && x.IsInterface && x.IsAssignableTo(startupType))
|
||||
.Where(x => !x.IsAbstract && !x.IsInterface && x.IsAssignableTo(startupType))
|
||||
.ToArray();
|
||||
|
||||
foreach (var type in startupTypes)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@using Moonlight.Client.UI.Layouts
|
||||
@using MoonCore.Blazor.Components
|
||||
@using Moonlight.Client.Services
|
||||
|
||||
@inject ApplicationAssemblyService ApplicationAssemblyService
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
@using Moonlight.Client.UI.Layouts
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISidebarItemProvider[] SidebarItemProviders
|
||||
@inject IEnumerable<ISidebarItemProvider> SidebarItemProviders
|
||||
|
||||
@{
|
||||
var url = new Uri(Navigation.Uri);
|
||||
|
||||
Reference in New Issue
Block a user