From 7f530238de238ec98b64a6d45d1336b7ae451a7b Mon Sep 17 00:00:00 2001 From: Ivan Sanz Carasa Date: Sun, 10 May 2020 10:56:15 +0200 Subject: [PATCH] Startup (#53) * Startup * release wiki only when release is created --- .github/workflows/publish-wiki.yml | 3 +- demo/Demo.sln | 43 +++++++++++++------ .../AssemblyWithStartup.csproj | 13 ++++++ .../Pages/AssemblyWithStartup.razor | 8 ++++ demo/LazyAreas/AssemblyWithStartup/Startup.cs | 32 ++++++++++++++ .../AssemblyWithStartup/_Imports.razor | 1 + .../LazyComponentFromNuget/wwwroot/.gitignore | 2 - demo/ModulesHost/ModulesHost.csproj | 2 + demo/WasmHost/Layout/NavMenu.razor | 5 +++ docs/Creating-a-Lazy-Loadable-Module.md | 1 + docs/Startup.md | 24 +++++++++++ docs/_Sidebar.md | 3 +- .../StartupExtensions.cs | 12 +++++- .../StartupExtensions.cs | 11 ++++- .../Abstractions/IAssemblyDataProvider.cs | 6 +++ .../Abstractions/IAssemblyLoader.cs | 7 ++- src/src/AssemblyLoader/AssemblyLoader.csproj | 1 + .../Services/AssemblyInitializer.cs | 37 ++++++++++++++++ .../AssemblyLoader/Services/AssemblyLoader.cs | 20 ++++++++- 19 files changed, 208 insertions(+), 23 deletions(-) create mode 100644 demo/LazyAreas/AssemblyWithStartup/AssemblyWithStartup.csproj create mode 100644 demo/LazyAreas/AssemblyWithStartup/Pages/AssemblyWithStartup.razor create mode 100644 demo/LazyAreas/AssemblyWithStartup/Startup.cs create mode 100644 demo/LazyAreas/AssemblyWithStartup/_Imports.razor delete mode 100644 demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore create mode 100644 docs/Startup.md create mode 100644 src/src/AssemblyLoader/Services/AssemblyInitializer.cs diff --git a/.github/workflows/publish-wiki.yml b/.github/workflows/publish-wiki.yml index 60d0396..8e47591 100644 --- a/.github/workflows/publish-wiki.yml +++ b/.github/workflows/publish-wiki.yml @@ -1,7 +1,8 @@ name: 'Publish Wiki' on: - push: + release: + types: [published, created, edited] branches: - master diff --git a/demo/Demo.sln b/demo/Demo.sln index b709f02..ed574e6 100644 --- a/demo/Demo.sln +++ b/demo/Demo.sln @@ -37,7 +37,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LazyAreas", "LazyAreas", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LazyComponentFromNuget", "LazyAreas\LazyComponentFromNuget\LazyComponentFromNuget.csproj", "{A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LazyComponentFromNuget", "LazyAreas\LazyComponentFromNuget\LazyComponentFromNuget.csproj", "{A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Imports", "Imports", "{7B174F1E-2091-4D48-9111-B52531C1B865}" ProjectSection(SolutionItems) = preProject @@ -47,6 +47,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Imports", "Imports", "{7B17 BlazorLazyLoading.Wasm.props = BlazorLazyLoading.Wasm.props EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssemblyWithStartup", "LazyAreas\AssemblyWithStartup\AssemblyWithStartup.csproj", "{DC9D8A4E-6491-4BC1-886C-C2DA94927786}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -129,18 +131,6 @@ Global {B78FC2FE-F107-49AB-95FC-E7F4559C879A}.Release|x64.Build.0 = Release|Any CPU {B78FC2FE-F107-49AB-95FC-E7F4559C879A}.Release|x86.ActiveCfg = Release|Any CPU {B78FC2FE-F107-49AB-95FC-E7F4559C879A}.Release|x86.Build.0 = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x64.ActiveCfg = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x64.Build.0 = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x86.ActiveCfg = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x86.Build.0 = Debug|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|Any CPU.Build.0 = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x64.ActiveCfg = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x64.Build.0 = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x86.ActiveCfg = Release|Any CPU - {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x86.Build.0 = Release|Any CPU {83419656-8137-4AEB-9A5B-74C7B85621F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {83419656-8137-4AEB-9A5B-74C7B85621F6}.Debug|Any CPU.Build.0 = Debug|Any CPU {83419656-8137-4AEB-9A5B-74C7B85621F6}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -153,6 +143,18 @@ Global {83419656-8137-4AEB-9A5B-74C7B85621F6}.Release|x64.Build.0 = Release|Any CPU {83419656-8137-4AEB-9A5B-74C7B85621F6}.Release|x86.ActiveCfg = Release|Any CPU {83419656-8137-4AEB-9A5B-74C7B85621F6}.Release|x86.Build.0 = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x64.ActiveCfg = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x64.Build.0 = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x86.ActiveCfg = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Debug|x86.Build.0 = Debug|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|Any CPU.Build.0 = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x64.ActiveCfg = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x64.Build.0 = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x86.ActiveCfg = Release|Any CPU + {9B062109-5E21-46CD-BDD1-315529E585E8}.Release|x86.Build.0 = Release|Any CPU {DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -177,6 +179,18 @@ Global {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x64.Build.0 = Release|Any CPU {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x86.ActiveCfg = Release|Any CPU {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x86.Build.0 = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|x64.ActiveCfg = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|x64.Build.0 = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|x86.ActiveCfg = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Debug|x86.Build.0 = Debug|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|Any CPU.Build.0 = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|x64.ActiveCfg = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|x64.Build.0 = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|x86.ActiveCfg = Release|Any CPU + {DC9D8A4E-6491-4BC1-886C-C2DA94927786}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -188,13 +202,14 @@ Global {E3E28F5C-3F96-4634-9528-10C23F2478DF} = {2DFA918F-9417-49B8-9FDA-E2231179978C} {6C5945E8-44F9-4898-AB78-FF0D85F5515B} = {2DFA918F-9417-49B8-9FDA-E2231179978C} {B78FC2FE-F107-49AB-95FC-E7F4559C879A} = {2DFA918F-9417-49B8-9FDA-E2231179978C} - {9B062109-5E21-46CD-BDD1-315529E585E8} = {E503BF43-DE57-4DB6-AF93-A5F765C94154} {83419656-8137-4AEB-9A5B-74C7B85621F6} = {2DFA918F-9417-49B8-9FDA-E2231179978C} + {9B062109-5E21-46CD-BDD1-315529E585E8} = {E503BF43-DE57-4DB6-AF93-A5F765C94154} {E503BF43-DE57-4DB6-AF93-A5F765C94154} = {2587AE99-7624-47E4-B6B8-79EC67346F67} {566D14F1-B2FB-463C-A627-C5EB23B763B7} = {2587AE99-7624-47E4-B6B8-79EC67346F67} {DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54} = {2587AE99-7624-47E4-B6B8-79EC67346F67} {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97} = {566D14F1-B2FB-463C-A627-C5EB23B763B7} {7B174F1E-2091-4D48-9111-B52531C1B865} = {2587AE99-7624-47E4-B6B8-79EC67346F67} + {DC9D8A4E-6491-4BC1-886C-C2DA94927786} = {566D14F1-B2FB-463C-A627-C5EB23B763B7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B979A335-AE81-406A-AADA-F236549D23D3} diff --git a/demo/LazyAreas/AssemblyWithStartup/AssemblyWithStartup.csproj b/demo/LazyAreas/AssemblyWithStartup/AssemblyWithStartup.csproj new file mode 100644 index 0000000..71438d2 --- /dev/null +++ b/demo/LazyAreas/AssemblyWithStartup/AssemblyWithStartup.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.1 + 3.0 + + + + + + + + diff --git a/demo/LazyAreas/AssemblyWithStartup/Pages/AssemblyWithStartup.razor b/demo/LazyAreas/AssemblyWithStartup/Pages/AssemblyWithStartup.razor new file mode 100644 index 0000000..e02f736 --- /dev/null +++ b/demo/LazyAreas/AssemblyWithStartup/Pages/AssemblyWithStartup.razor @@ -0,0 +1,8 @@ +@page "/startup" + +

Assembly with Startup

+

+ This page is contained in AssemblyWithStartup.dll.
+ This Assembly contains a Startup class that shows an alert() when it gets loaded. +

+ diff --git a/demo/LazyAreas/AssemblyWithStartup/Startup.cs b/demo/LazyAreas/AssemblyWithStartup/Startup.cs new file mode 100644 index 0000000..ea08480 --- /dev/null +++ b/demo/LazyAreas/AssemblyWithStartup/Startup.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; +using Microsoft.JSInterop; + +namespace AssemblyWithStartup +{ + public class Startup + { + private readonly IJSRuntime _jsRuntime; + + public Startup(IJSRuntime jsRuntime) + { + _jsRuntime = jsRuntime; + } + + public Task Configure() + { + return Alert("Hello from Startup! The assembly 'AssemblyWithStartup' has been loaded ;)"); + } + + private async Task Alert(string message) + { + // avoid crash on prerendering + try + { + await _jsRuntime.InvokeVoidAsync("alert", message).ConfigureAwait(false); + } + catch (Exception) + { } + } + } +} diff --git a/demo/LazyAreas/AssemblyWithStartup/_Imports.razor b/demo/LazyAreas/AssemblyWithStartup/_Imports.razor new file mode 100644 index 0000000..7728512 --- /dev/null +++ b/demo/LazyAreas/AssemblyWithStartup/_Imports.razor @@ -0,0 +1 @@ +@using Microsoft.AspNetCore.Components.Web diff --git a/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore b/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore deleted file mode 100644 index 924b93c..0000000 --- a/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -_lazy/ -_lazy.json diff --git a/demo/ModulesHost/ModulesHost.csproj b/demo/ModulesHost/ModulesHost.csproj index 57fb4e8..3dae2ba 100644 --- a/demo/ModulesHost/ModulesHost.csproj +++ b/demo/ModulesHost/ModulesHost.csproj @@ -8,12 +8,14 @@ + + diff --git a/demo/WasmHost/Layout/NavMenu.razor b/demo/WasmHost/Layout/NavMenu.razor index ffab070..943e3e2 100644 --- a/demo/WasmHost/Layout/NavMenu.razor +++ b/demo/WasmHost/Layout/NavMenu.razor @@ -22,6 +22,11 @@ Lazy Component from Nuget +