[Blazor] Lazy loading - Complete example - Prevent repeated loads (#34243)

pull/34345/head
Robert Haken 2024-12-12 13:23:57 +01:00 committed by GitHub
parent a5766e2355
commit 9092b764ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -592,16 +592,18 @@ The assembly is assigned to <xref:Microsoft.AspNetCore.Components.Routing.Router
@code {
private List<Assembly> lazyLoadedAssemblies = new();
private bool grantImaharaRobotControlsAssemblyLoaded;
private async Task OnNavigateAsync(NavigationContext args)
{
try
{
if (args.Path == "robot")
if ((args.Path == "robot") && !grantImaharaRobotControlsAssemblyLoaded)
{
var assemblies = await AssemblyLoader.LoadAssembliesAsync(
new[] { "GrantImaharaRobotControls.{FILE EXTENSION}" });
lazyLoadedAssemblies.AddRange(assemblies);
grantImaharaRobotControlsAssemblyLoaded = true;
}
}
catch (Exception ex)
@ -644,16 +646,18 @@ The assembly is assigned to <xref:Microsoft.AspNetCore.Components.Routing.Router
@code {
private List<Assembly> lazyLoadedAssemblies = new List<Assembly>();
private bool grantImaharaRobotControlsAssemblyLoaded;
private async Task OnNavigateAsync(NavigationContext args)
{
try
{
if (args.Path == "robot")
if ((args.Path == "robot") && !grantImaharaRobotControlsAssemblyLoaded)
{
var assemblies = await AssemblyLoader.LoadAssembliesAsync(
new[] { "GrantImaharaRobotControls.{FILE EXTENSION}" });
lazyLoadedAssemblies.AddRange(assemblies);
grantImaharaRobotControlsAssemblyLoaded = true;
}
}
catch (Exception ex)