From d242dd5a84376a6e529c0c923d9674d78db0973f Mon Sep 17 00:00:00 2001 From: StardustDL <34736356+StardustDL@users.noreply.github.com> Date: Thu, 4 Mar 2021 15:03:15 +0800 Subject: [PATCH] Add startup & manifest for razor component modules. (#17) #16 --- .github/workflows/ci.yml | 4 +- README.md | 19 ++++- build/Build.csproj | 4 +- build/IntegrationTask.cs | 4 +- global.json | 5 -- .../RazorComponentClientModule.cs | 35 +------- .../RazorComponentClientModuleCollection.cs | 22 ++++- .../RazorComponentClientModuleExtensions.cs | 82 ++++++++++++++++++- .../RazorComponentClientModuleManifest.cs | 22 +++++ ...zorComponentClientModuleManifestBuilder.cs | 45 ++++++++++ .../RazorComponentClientModulePlugin.cs | 38 +++++++++ .../RazorComponentClientModuleStartup.cs | 24 ++++++ .../UI/GlobalComponentDeclare.razor | 4 +- .../UI/ScriptDeclare.razor | 4 +- .../UI/StyleSheetDeclare.razor | 4 +- .../Hosting/IModuleHostBuilderPlugin.cs | 20 +++-- .../Hosting/ModuleHostBuilder.cs | 24 +++--- .../GraphQLServerModuleExtensions.cs | 3 +- .../GraphQLServerModulePlugin.cs | 4 +- .../Context/ModuleTestContext.cs | 12 +-- .../Modulight.Modules.Test.csproj | 2 +- .../Modulight.UI.Blazor.Hosting.csproj | 2 +- .../Modulight.UI.Blazor.csproj | 4 +- .../Pages/Index.razor | 2 +- .../Delights.Modules.Hello.csproj | 6 +- .../Properties/launchSettings.json | 2 +- test/Test.Modulights.UI/Startup.cs | 3 +- .../Test.Modulights.UI.csproj | 4 - test/Test.Modulights/LifetimeTest.cs | 5 -- test/Test.Modulights/Test.Modulights.csproj | 13 +-- 30 files changed, 309 insertions(+), 113 deletions(-) delete mode 100644 global.json create mode 100644 src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifest.cs create mode 100644 src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifestBuilder.cs create mode 100644 src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModulePlugin.cs create mode 100644 src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleStartup.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eb2bdf..4aa4372 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,8 @@ jobs: uses: actions/checkout@v2 - name: Install docfx run: choco install docfx -y - - name: Publish - run: ./build.ps1 -t publish + - name: Integration + run: ./build.ps1 -t integration - name: Upload artifacts uses: actions/upload-artifact@v2 with: diff --git a/README.md b/README.md index 0a6656b..f1612af 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ It provides a place to unify resources, and it can be used to make Razor compone 1. Register modules. -For general modules (includes Razor component & AspNet server modules): +For general modules: ```cs services.AddModules(builder => { @@ -32,21 +32,36 @@ services.AddModules(builder => { }); ``` -2. Configure the module initilizing & shutdown. +1. Configure the module initilizing & shutdown. ```cs var host = services.GetModuleHost(); await host.Initialize(); + +// do something + await host.Shutdown(); +// Or use context: + // context: IServiceProvider services (provided by package Modulight.Modules.Core) await using var _ = await services.UseModuleHost(); + +// do something ``` ### Addition steps #### Use Razor component modules +```cs +// in Startup: void ConfigureServices(ISeviceCollection services) + +services.AddModules(builder => { + builder.UseRazorComponentClientModules().AddModule(); +}); +``` + For razor components, add `ResourceDeclare` component to App.razor to load UI resources. ```razor diff --git a/build/Build.csproj b/build/Build.csproj index cef4c6e..5db7ac3 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -6,9 +6,9 @@ enable - + - + \ No newline at end of file diff --git a/build/IntegrationTask.cs b/build/IntegrationTask.cs index 27059e4..34af548 100644 --- a/build/IntegrationTask.cs +++ b/build/IntegrationTask.cs @@ -3,10 +3,8 @@ namespace Build { [TaskName("Integration")] - [IsDependentOn(typeof(BuildTask))] [IsDependentOn(typeof(TestTask))] - [IsDependentOn(typeof(PackTask))] - [IsDependentOn(typeof(DocumentTask))] + [IsDependentOn(typeof(PublishTask))] public class IntegrationTask : FrostingTask { diff --git a/global.json b/global.json deleted file mode 100644 index 8c50959..0000000 --- a/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sdk": { - "version": "5.0.103" - } -} \ No newline at end of file diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModule.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModule.cs index fb580d7..496e1af 100644 --- a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModule.cs +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModule.cs @@ -20,16 +20,6 @@ public interface IRazorComponentClientModule : IModule /// RenderFragment? Icon { get; } - /// - /// Get module UI resources. - /// - UIResource[] Resources { get; } - - /// - /// Get global components. - /// - Type[] GlobalComponents { get; } - /// /// Get module UI route root path, such as home, search, and so on. /// Use for no page module. @@ -63,24 +53,7 @@ protected RazorComponentClientModule(IModuleHost host) : base(host) if (attr is not null) RootPath = attr.RootPath; } - { - var attrs = type.GetCustomAttributes(); - List resources = new List(); - foreach (var attr in attrs) - { - resources.Add(new UIResource(attr.Type, attr.Path) { Attributes = attr.Attributes }); - } - Resources = resources.ToArray(); - } - { - var attrs = type.GetCustomAttributes(); - List resources = new List(); - foreach (var attr in attrs) - { - resources.Add(attr.Type); - } - GlobalComponents = resources.ToArray(); - } + } /// @@ -99,12 +72,6 @@ public virtual bool Contains(string path) path = path.Trim('/') + "/"; return path.StartsWith($"{RootPath}/"); } - - /// - public UIResource[] Resources { get; protected set; } - - /// - public Type[] GlobalComponents { get; protected set; } } [Module(Author = "StardustDL", Description = "Provide services for razor component client modules.", Url = "https://github.com/StardustDL/delights")] diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleCollection.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleCollection.cs index 16fbe2f..9f6c332 100644 --- a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleCollection.cs +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleCollection.cs @@ -13,11 +13,17 @@ namespace Modulight.Modules.Client.RazorComponents { + /// /// Specifies the contract for razor component module hosts. /// public interface IRazorComponentClientModuleCollection : IModuleCollection { + /// + /// Get manifest for the module. + /// + RazorComponentClientModuleManifest GetManifest(Type module); + /// /// Load related assemblies for a given route. /// @@ -58,9 +64,15 @@ public static class RazorComponentClientModuleCollectionExtensions internal class RazorComponentClientModuleCollection : ModuleHostFilterCollection, IRazorComponentClientModuleCollection { + Dictionary Manifests { get; } = new Dictionary(); + public RazorComponentClientModuleCollection(IModuleHost host) : base(host) { Logger = host.Services.GetRequiredService>(); + foreach (var item in host.Services.GetServices()) + { + Manifests.Add(item.Type, item.Manifest); + } } public ILogger Logger { get; } @@ -77,9 +89,9 @@ public async Task LoadResources(Type? moduleType = null) targetModules = targetModules.Where(x => x.GetType().IsModule(moduleType)); } - foreach (var module in targetModules) + foreach (var manifest in Manifests.Values) { - foreach (var resource in module.Resources) + foreach (var resource in manifest.Resources) { try { @@ -95,7 +107,7 @@ public async Task LoadResources(Type? moduleType = null) } catch (JSException ex) { - Logger.LogError(ex, $"Failed to load resource {resource.Path} in module {module.Manifest.Name}"); + Logger.LogError(ex, $"Failed to load resource {resource.Path}"); } } } @@ -141,7 +153,7 @@ public async Task> GetAssembliesForRouting(string path, bool recu if (module.Contains(path)) { - foreach (var resource in module.Resources.Where(x => x.Type is UIResourceType.Assembly)) + foreach (var resource in GetManifest(module.GetType()).Resources.Where(x => x.Type is UIResourceType.Assembly)) { cancellationToken.ThrowIfCancellationRequested(); @@ -207,5 +219,7 @@ public async Task> GetAssembliesForRouting(string path, bool recu return results; } + + public RazorComponentClientModuleManifest GetManifest(Type module) => Manifests[module]; } } \ No newline at end of file diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleExtensions.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleExtensions.cs index ebe4a33..d95ba11 100644 --- a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleExtensions.cs +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleExtensions.cs @@ -1,7 +1,11 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Modulight.Modules.Client.RazorComponents.UI; using Modulight.Modules.Hosting; using System; +using System.Collections.Generic; +using System.Reflection; namespace Modulight.Modules.Client.RazorComponents { @@ -10,11 +14,87 @@ namespace Modulight.Modules.Client.RazorComponents /// public static class RazorComponentClientModuleExtensions { + /// + /// Use building plugin for graphql modules. + /// + /// + /// + public static IModuleHostBuilder UseRazorComponentClientModules(this IModuleHostBuilder modules) + { + return modules.ConfigureBuilderServices(services => + { + services.TryAddTransient(); + }).UsePlugin(); + } + /// /// Get razor component module host from service provider. /// /// /// public static IRazorComponentClientModuleCollection GetRazorComponentClientModuleCollection(this IServiceProvider provider) => provider.GetRequiredService(); + + /// + /// Add resource to manifest. + /// + /// + /// + /// + public static IRazorComponentClientModuleManifestBuilder WithResource(this IRazorComponentClientModuleManifestBuilder builder, UIResource resource) + { + builder.Resources.Add(resource); + return builder; + } + + /// + /// Add global component to manifest. + /// + /// + /// + /// + public static IRazorComponentClientModuleManifestBuilder WithGlobalComponent(this IRazorComponentClientModuleManifestBuilder builder, Type type) + { + builder.GlobalComponents.Add(type); + return builder; + } + + /// + /// Add global component to manifest. + /// + /// + /// + /// + public static IRazorComponentClientModuleManifestBuilder WithGlobalComponent(this IRazorComponentClientModuleManifestBuilder builder) where T : IComponent + { + builder.GlobalComponents.Add(typeof(T)); + return builder; + } + + /// + /// Configure the builder by default from attributes. + /// + /// + /// + /// + public static IRazorComponentClientModuleManifestBuilder WithDefaultsFromModuleType(this IRazorComponentClientModuleManifestBuilder builder, Type type) + { + { + var attrs = type.GetCustomAttributes(); + List resources = new List(); + foreach (var attr in attrs) + { + builder.WithResource(new UIResource(attr.Type, attr.Path) { Attributes = attr.Attributes }); + } + } + { + var attrs = type.GetCustomAttributes(); + List resources = new List(); + foreach (var attr in attrs) + { + builder.WithGlobalComponent(attr.Type); + } + } + return builder; + } } } diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifest.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifest.cs new file mode 100644 index 0000000..4896a69 --- /dev/null +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifest.cs @@ -0,0 +1,22 @@ +using Modulight.Modules.Client.RazorComponents.UI; +using System; +using System.Linq; + +namespace Modulight.Modules.Client.RazorComponents +{ + /// + /// Manifest for . + /// + public record RazorComponentClientModuleManifest + { + /// + /// Get module UI resources. + /// + public UIResource[] Resources { get; init; } = Array.Empty(); + + /// + /// Get global components. + /// + public Type[] GlobalComponents { get; init; } = Array.Empty(); + } +} diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifestBuilder.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifestBuilder.cs new file mode 100644 index 0000000..c0833a9 --- /dev/null +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleManifestBuilder.cs @@ -0,0 +1,45 @@ +using Modulight.Modules.Client.RazorComponents.UI; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Modulight.Modules.Client.RazorComponents +{ + /// + /// Specifies the interface to build a module manifest. + /// + public interface IRazorComponentClientModuleManifestBuilder + { + /// + /// Get module UI resources. + /// + IList Resources { get; } + + /// + /// Get global components. + /// + IList GlobalComponents { get; } + + /// + /// Build the manifest. + /// + /// + RazorComponentClientModuleManifest Build(); + } + + class DefaultRazorComponentClientModuleManifestBuilder : IRazorComponentClientModuleManifestBuilder + { + public IList Resources { get; } = new List(); + + public IList GlobalComponents { get; } = new List(); + + public RazorComponentClientModuleManifest Build() + { + return new RazorComponentClientModuleManifest + { + GlobalComponents = GlobalComponents.ToArray(), + Resources = Resources.ToArray() + }; + } + } +} diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModulePlugin.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModulePlugin.cs new file mode 100644 index 0000000..710a937 --- /dev/null +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModulePlugin.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.DependencyInjection; +using Modulight.Modules.Hosting; +using System; +using System.Collections.Generic; + +namespace Modulight.Modules.Client.RazorComponents +{ + internal record ModuleManifestItem(Type Type, RazorComponentClientModuleManifest Manifest); + + internal sealed class RazorComponentClientModulePlugin : ModuleHostBuilderPlugin + { + public override void BeforeBuild(IList modules, IServiceCollection services, IServiceProvider builderServices) + { + + base.BeforeBuild(modules, services, builderServices); + } + + public override void AfterModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) + { + if (module.Type.IsModule()) + { + var manifestBuilder = builderServices.GetRequiredService(); + manifestBuilder.WithDefaultsFromModuleType(module.Type); + + if (module.Startup is IRazorComponentClientModuleStartup startup) + { + startup.ConfigureRazorComponentClientModuleManifest(manifestBuilder); + } + + var manifest = manifestBuilder.Build(); + + services.AddSingleton(new ModuleManifestItem(module.Type, manifest)); + } + base.AfterModule(module, services, builderServices); + } + } + +} \ No newline at end of file diff --git a/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleStartup.cs b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleStartup.cs new file mode 100644 index 0000000..1bfd0a7 --- /dev/null +++ b/src/Modulight.Modules.Client.RazorComponents/RazorComponentClientModuleStartup.cs @@ -0,0 +1,24 @@ +namespace Modulight.Modules.Client.RazorComponents +{ + + /// + /// Startup for graphql server module. + /// + public interface IRazorComponentClientModuleStartup : IModuleStartup + { + /// + /// Configure manifest for razor component module. + /// + /// + void ConfigureRazorComponentClientModuleManifest(IRazorComponentClientModuleManifestBuilder builder); + } + + /// + /// Empty implementation for . + /// + public abstract class RazorComponentClientModuleStartup : ModuleStartup, IRazorComponentClientModuleStartup + { + /// + public virtual void ConfigureRazorComponentClientModuleManifest(IRazorComponentClientModuleManifestBuilder builder) { } + } +} \ No newline at end of file diff --git a/src/Modulight.Modules.Client.RazorComponents/UI/GlobalComponentDeclare.razor b/src/Modulight.Modules.Client.RazorComponents/UI/GlobalComponentDeclare.razor index 9b9b349..e7a3b5f 100644 --- a/src/Modulight.Modules.Client.RazorComponents/UI/GlobalComponentDeclare.razor +++ b/src/Modulight.Modules.Client.RazorComponents/UI/GlobalComponentDeclare.razor @@ -5,9 +5,9 @@ @code{ private RenderFragment ComponentDeclared() => builder => { - foreach (var c in ModuleHost.LoadedModules) + foreach (var c in ModuleHost.DefinedModules) { - foreach (var r in c.GlobalComponents) + foreach (var r in ModuleHost.GetManifest(c).GlobalComponents) { builder.OpenComponent(0, r); builder.CloseComponent(); diff --git a/src/Modulight.Modules.Client.RazorComponents/UI/ScriptDeclare.razor b/src/Modulight.Modules.Client.RazorComponents/UI/ScriptDeclare.razor index 6a19ad4..ecec6b1 100644 --- a/src/Modulight.Modules.Client.RazorComponents/UI/ScriptDeclare.razor +++ b/src/Modulight.Modules.Client.RazorComponents/UI/ScriptDeclare.razor @@ -1,9 +1,9 @@ @inject IRazorComponentClientModuleCollection ModuleHost @inject IServiceProvider ServiceProvider -@foreach (var c in ModuleHost.LoadedModules) +@foreach (var c in ModuleHost.DefinedModules) { - foreach (var r in c.Resources.Where(x => x.Type is UIResourceType.Script)) + foreach (var r in ModuleHost.GetManifest(c).Resources.Where(x => x.Type is UIResourceType.Script)) { @((MarkupString)($"")) } diff --git a/src/Modulight.Modules.Client.RazorComponents/UI/StyleSheetDeclare.razor b/src/Modulight.Modules.Client.RazorComponents/UI/StyleSheetDeclare.razor index 2e03a0b..10e5dec 100644 --- a/src/Modulight.Modules.Client.RazorComponents/UI/StyleSheetDeclare.razor +++ b/src/Modulight.Modules.Client.RazorComponents/UI/StyleSheetDeclare.razor @@ -1,9 +1,9 @@ @inject IRazorComponentClientModuleCollection ModuleHost @inject IServiceProvider ServiceProvider -@foreach (var c in ModuleHost.LoadedModules) +@foreach (var c in ModuleHost.DefinedModules) { - foreach (var r in c.Resources.Where(x => x.Type is UIResourceType.StyleSheet)) + foreach (var r in ModuleHost.GetManifest(c).Resources.Where(x => x.Type is UIResourceType.StyleSheet)) { @((MarkupString)($"")) } diff --git a/src/Modulight.Modules.Core/Hosting/IModuleHostBuilderPlugin.cs b/src/Modulight.Modules.Core/Hosting/IModuleHostBuilderPlugin.cs index 94db597..523a8d6 100644 --- a/src/Modulight.Modules.Core/Hosting/IModuleHostBuilderPlugin.cs +++ b/src/Modulight.Modules.Core/Hosting/IModuleHostBuilderPlugin.cs @@ -14,28 +14,32 @@ public interface IModuleHostBuilderPlugin /// /// /// - void AfterBuild(ModuleDefinition[] modules, IServiceCollection services); + /// + void AfterBuild(ModuleDefinition[] modules, IServiceCollection services, IServiceProvider builderServices); /// /// Do after the module registered. /// /// /// - void AfterModule(ModuleDefinition module, IServiceCollection services); + /// + void AfterModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices); /// /// Do before the host is building. /// /// /// - void BeforeBuild(IList modules, IServiceCollection services); + /// + void BeforeBuild(IList modules, IServiceCollection services, IServiceProvider builderServices); /// /// Do before the module is registering. /// /// /// - void BeforeModule(ModuleDefinition module, IServiceCollection services); + /// + void BeforeModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices); } /// @@ -44,15 +48,15 @@ public interface IModuleHostBuilderPlugin public abstract class ModuleHostBuilderPlugin : IModuleHostBuilderPlugin { /// - public virtual void BeforeBuild(IList modules, IServiceCollection services) { } + public virtual void BeforeBuild(IList modules, IServiceCollection services, IServiceProvider builderServices) { } /// - public virtual void AfterBuild(ModuleDefinition[] modules, IServiceCollection services) { } + public virtual void AfterBuild(ModuleDefinition[] modules, IServiceCollection services, IServiceProvider builderServices) { } /// - public virtual void BeforeModule(ModuleDefinition module, IServiceCollection services) { } + public virtual void BeforeModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) { } /// - public virtual void AfterModule(ModuleDefinition module, IServiceCollection services) { } + public virtual void AfterModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) { } } } \ No newline at end of file diff --git a/src/Modulight.Modules.Core/Hosting/ModuleHostBuilder.cs b/src/Modulight.Modules.Core/Hosting/ModuleHostBuilder.cs index a15789e..7e2592d 100644 --- a/src/Modulight.Modules.Core/Hosting/ModuleHostBuilder.cs +++ b/src/Modulight.Modules.Core/Hosting/ModuleHostBuilder.cs @@ -71,36 +71,36 @@ public virtual IModuleHostBuilder UsePlugin(Type type) return this; } - protected virtual void BeforeBuild(IList modules, IServiceCollection services, IReadOnlyList plugins) + protected virtual void BeforeBuild(IList modules, IServiceCollection services, IReadOnlyList plugins, IServiceProvider builderServices) { foreach (var plugin in plugins) { - plugin.BeforeBuild(modules, services); + plugin.BeforeBuild(modules, services, builderServices); } services.AddLogging().AddOptions(); } - protected virtual void AfterBuild(IServiceCollection services, ModuleDefinition[] modules, IReadOnlyList plugins) + protected virtual void AfterBuild(IServiceCollection services, ModuleDefinition[] modules, IReadOnlyList plugins, IServiceProvider builderServices) { foreach (var plugin in plugins) { - plugin.AfterBuild(modules, services); + plugin.AfterBuild(modules, services, builderServices); } } - protected virtual void BeforeModule(IServiceCollection services, ModuleDefinition module, IReadOnlyList plugins) + protected virtual void BeforeModule(IServiceCollection services, ModuleDefinition module, IReadOnlyList plugins, IServiceProvider builderServices) { foreach (var plugin in plugins) { - plugin.BeforeModule(module, services); + plugin.BeforeModule(module, services, builderServices); } } - protected virtual void AfterModule(IServiceCollection services, ModuleDefinition module, IReadOnlyList plugins) + protected virtual void AfterModule(IServiceCollection services, ModuleDefinition module, IReadOnlyList plugins, IServiceProvider builderServices) { foreach (var plugin in plugins) { - plugin.AfterModule(module, services); + plugin.AfterModule(module, services, builderServices); } } @@ -223,7 +223,7 @@ void addModule(Type type) IList initialModules = new List(Modules.ToArray()); - BeforeBuild(initialModules, services, plugins); + BeforeBuild(initialModules, services, plugins, builderService); var modules = ResolveModuleDependency(initialModules, builderService); Dictionary moduleStartups = new Dictionary(); @@ -239,7 +239,7 @@ void addModule(Type type) startup.ConfigureServices(services); } - BeforeModule(services, definition, plugins); + BeforeModule(services, definition, plugins, builderService); services.AddSingleton(type); foreach (var service in manifest.Services) @@ -257,12 +257,12 @@ void addModule(Type type) } - AfterModule(services, definition, plugins); + AfterModule(services, definition, plugins, builderService); logger.LogInformation($"Processed module {type.FullName}."); } - AfterBuild(services, modules.ToArray(), plugins); + AfterBuild(services, modules.ToArray(), plugins, builderService); var definedModules = modules.Select(x => (x.Type, x.Manifest)).ToArray(); services.TryAddSingleton(sp => new DefaultModuleHost(sp, definedModules)); diff --git a/src/Modulight.Modules.Server.GraphQL/GraphQLServerModuleExtensions.cs b/src/Modulight.Modules.Server.GraphQL/GraphQLServerModuleExtensions.cs index 61e3132..f0ebf3b 100644 --- a/src/Modulight.Modules.Server.GraphQL/GraphQLServerModuleExtensions.cs +++ b/src/Modulight.Modules.Server.GraphQL/GraphQLServerModuleExtensions.cs @@ -12,8 +12,7 @@ namespace Modulight.Modules.Server.GraphQL public static class GraphQLServerModuleExtensions { /// - /// Use building middlewares for graphql modules. - /// It will register service. + /// Use building plugin for graphql modules. /// /// /// diff --git a/src/Modulight.Modules.Server.GraphQL/GraphQLServerModulePlugin.cs b/src/Modulight.Modules.Server.GraphQL/GraphQLServerModulePlugin.cs index d0c5e21..7745fc1 100644 --- a/src/Modulight.Modules.Server.GraphQL/GraphQLServerModulePlugin.cs +++ b/src/Modulight.Modules.Server.GraphQL/GraphQLServerModulePlugin.cs @@ -8,7 +8,7 @@ namespace Modulight.Modules.Server.GraphQL { internal sealed class GraphQLServerModulePlugin : ModuleHostBuilderPlugin { - public override void AfterModule(ModuleDefinition module, IServiceCollection services) + public override void AfterModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) { if (module.Type.IsModule()) { @@ -37,7 +37,7 @@ public override void AfterModule(ModuleDefinition module, IServiceCollection ser builder.AddFiltering().AddSorting().AddProjections(); } } - base.AfterModule(module, services); + base.AfterModule(module, services, builderServices); } } } diff --git a/src/Modulight.Modules.Test/Context/ModuleTestContext.cs b/src/Modulight.Modules.Test/Context/ModuleTestContext.cs index fe37c3c..889afa1 100644 --- a/src/Modulight.Modules.Test/Context/ModuleTestContext.cs +++ b/src/Modulight.Modules.Test/Context/ModuleTestContext.cs @@ -21,29 +21,29 @@ class ModuleHostBuilderCollector : ModuleHostBuilderPlugin public List ModuleProcessingOrder { get; } = new List(); - public override void BeforeModule(ModuleDefinition module, IServiceCollection services) + public override void BeforeModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) { ModuleProcessingOrder.Add(module.Type); - base.BeforeModule(module, services); + base.BeforeModule(module, services, builderServices); } - public override void AfterModule(ModuleDefinition module, IServiceCollection services) + public override void AfterModule(ModuleDefinition module, IServiceCollection services, IServiceProvider builderServices) { if (Options.StartupChecking.TryGetValue(module.Type, out var startupType)) { Assert.IsNotNull(module.Startup, "The startup is unexpected null."); Assert.AreEqual(startupType, module.Startup!.GetType(), "Startup type is not the same."); } - base.AfterModule(module, services); + base.AfterModule(module, services, builderServices); } - public override void AfterBuild(ModuleDefinition[] modules, IServiceCollection services) + public override void AfterBuild(ModuleDefinition[] modules, IServiceCollection services, IServiceProvider builderServices) { services.AddSingleton(new ModuleHostBuilderLog { ModuleProcessingOrder = ModuleProcessingOrder.ToArray() }); - base.AfterBuild(modules, services); + base.AfterBuild(modules, services, builderServices); } } diff --git a/src/Modulight.Modules.Test/Modulight.Modules.Test.csproj b/src/Modulight.Modules.Test/Modulight.Modules.Test.csproj index ec8a6e5..853a426 100644 --- a/src/Modulight.Modules.Test/Modulight.Modules.Test.csproj +++ b/src/Modulight.Modules.Test/Modulight.Modules.Test.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Modulight.UI.Blazor.Hosting/Modulight.UI.Blazor.Hosting.csproj b/src/Modulight.UI.Blazor.Hosting/Modulight.UI.Blazor.Hosting.csproj index c1c7e17..290c903 100644 --- a/src/Modulight.UI.Blazor.Hosting/Modulight.UI.Blazor.Hosting.csproj +++ b/src/Modulight.UI.Blazor.Hosting/Modulight.UI.Blazor.Hosting.csproj @@ -21,11 +21,11 @@ - + diff --git a/src/Modulight.UI.Blazor/Modulight.UI.Blazor.csproj b/src/Modulight.UI.Blazor/Modulight.UI.Blazor.csproj index bbbe673..cb7b681 100644 --- a/src/Modulight.UI.Blazor/Modulight.UI.Blazor.csproj +++ b/src/Modulight.UI.Blazor/Modulight.UI.Blazor.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/src/modules/hello/Delights.Modules.Hello.UI/Pages/Index.razor b/src/modules/hello/Delights.Modules.Hello.UI/Pages/Index.razor index 09fec38..119c4e8 100644 --- a/src/modules/hello/Delights.Modules.Hello.UI/Pages/Index.razor +++ b/src/modules/hello/Delights.Modules.Hello.UI/Pages/Index.razor @@ -24,7 +24,7 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - messages = (await Service.GraphQLClient.GetMessagesQuery.ExecuteAsync()).Data?.Messages?.Nodes?.ToList() ?? new List(); + messages = (await Service.GraphQLClient.GetMessages.ExecuteAsync()).Data?.Messages?.Nodes?.ToList() ?? new List(); } void OnClick() diff --git a/src/modules/hello/Delights.Modules.Hello/Delights.Modules.Hello.csproj b/src/modules/hello/Delights.Modules.Hello/Delights.Modules.Hello.csproj index 8f67e99..1497c77 100644 --- a/src/modules/hello/Delights.Modules.Hello/Delights.Modules.Hello.csproj +++ b/src/modules/hello/Delights.Modules.Hello/Delights.Modules.Hello.csproj @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/Test.Modulights.UI/Properties/launchSettings.json b/test/Test.Modulights.UI/Properties/launchSettings.json index 62b770c..9c7be7e 100644 --- a/test/Test.Modulights.UI/Properties/launchSettings.json +++ b/test/Test.Modulights.UI/Properties/launchSettings.json @@ -19,7 +19,7 @@ "commandName": "Project", "dotnetRunMessages": "true", "launchBrowser": true, - "applicationUrl": "https://localhost:5001;http://localhost:5000", + "applicationUrl": "https://localhost:5001;http://localhost:5002", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/test/Test.Modulights.UI/Startup.cs b/test/Test.Modulights.UI/Startup.cs index 5c90848..4fbea4e 100644 --- a/test/Test.Modulights.UI/Startup.cs +++ b/test/Test.Modulights.UI/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Modulight.Modules.Client.RazorComponents; using Modulight.Modules.Hosting; using Modulight.Modules.Server.AspNet; using Modulight.Modules.Server.GraphQL; @@ -34,7 +35,7 @@ public void ConfigureServices(IServiceCollection services) { services.AddModules(builder => { - builder.AddServerSideBlazorUI().AddModule() + builder.UseRazorComponentClientModules().AddServerSideBlazorUI().AddModule() .AddHelloModule((o, _) => o.GraphQLEndpoint = "https://localhost:5001/graphql"); builder.UseGraphQLServerModules() .AddHelloServerModule(); diff --git a/test/Test.Modulights.UI/Test.Modulights.UI.csproj b/test/Test.Modulights.UI/Test.Modulights.UI.csproj index 52f36ae..ef9584c 100644 --- a/test/Test.Modulights.UI/Test.Modulights.UI.csproj +++ b/test/Test.Modulights.UI/Test.Modulights.UI.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/test/Test.Modulights/LifetimeTest.cs b/test/Test.Modulights/LifetimeTest.cs index ddf3aaf..0ff44ba 100644 --- a/test/Test.Modulights/LifetimeTest.cs +++ b/test/Test.Modulights/LifetimeTest.cs @@ -32,11 +32,6 @@ await context.Run(host => var module = host.EnsureGetLoadedModule(); Assert.IsTrue(module.HasInitialized); Assert.IsFalse(module.HasShutdowned); - }, host => - { - var module = host.EnsureGetLoadedModule(); - Assert.IsTrue(module.HasInitialized); - Assert.IsTrue(module.HasShutdowned); }); } } diff --git a/test/Test.Modulights/Test.Modulights.csproj b/test/Test.Modulights/Test.Modulights.csproj index 920fbed..f6f8554 100644 --- a/test/Test.Modulights/Test.Modulights.csproj +++ b/test/Test.Modulights/Test.Modulights.csproj @@ -7,14 +7,17 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + +