-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Startup * release wiki only when release is created
- Loading branch information
Showing
19 changed files
with
208 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
name: 'Publish Wiki' | ||
|
||
on: | ||
push: | ||
release: | ||
types: [published, created, edited] | ||
branches: | ||
- master | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
demo/LazyAreas/AssemblyWithStartup/AssemblyWithStartup.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<RazorLangVersion>3.0</RazorLangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
demo/LazyAreas/AssemblyWithStartup/Pages/AssemblyWithStartup.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@page "/startup" | ||
|
||
<h1>Assembly with Startup</h1> | ||
<p> | ||
This page is contained in <code>AssemblyWithStartup.dll</code>.<br /> | ||
This Assembly contains a Startup class that shows an <code>alert()</code> when it gets loaded. | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
{ } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@using Microsoft.AspNetCore.Components.Web |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
There are some cases where you require to run some actions right after a lazy **Assembly** or **Module** is loaded. This section covers the **Startup** class and how to use it. | ||
|
||
# Creating a Startup (optional) | ||
|
||
In order to create a valid **Startup** for your Assembly, it just needs to include a *public class* called `Startup` with a *public* `Configure()` method: | ||
|
||
```cs | ||
public class Startup | ||
{ | ||
// (optional) DI constructor | ||
// public Startup(...) { } | ||
// (alternative) public void Configure() | ||
public Task Configure() | ||
{ | ||
Console.WriteLine("Startup Called!"); | ||
return Task.Delay(2000); | ||
} | ||
} | ||
``` | ||
|
||
As you might probably noticed, the `Startup` **constructor** accept parameters **injected** from the current `IServiceProvider`. | ||
|
||
That's all! The next time the assembly gets loaded it will find, construct and `await` your `Startup.Configure()` implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BlazorLazyLoading.Services | ||
{ | ||
public static class AssemblyInitializer | ||
{ | ||
public static Task ConfigureAssembly(Assembly assembly, IServiceProvider services) | ||
{ | ||
var startupTypes = assembly.GetTypes() | ||
.Where(t => t.Name == "Startup") | ||
.Where(t => t.GetMethod("Configure", Array.Empty<Type>()) != null) | ||
.ToList(); | ||
|
||
if (startupTypes.Count != 1) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
var startupType = startupTypes.First(); | ||
var configureMethod = startupType.GetMethod("Configure", Array.Empty<Type>()); | ||
|
||
var startup = ActivatorUtilities.CreateInstance(services, startupType); | ||
object result = configureMethod.Invoke(startup, Array.Empty<object>()); | ||
|
||
if (result is Task resultTask) | ||
{ | ||
return resultTask; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.