Skip to content

Commit

Permalink
[Blazor] Lazy loading - Complete example - Prevent repeated loads (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
hakenr authored Dec 12, 2024
1 parent a5766e2 commit 9092b76
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aspnetcore/blazor/webassembly-lazy-load-assemblies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9092b76

Please sign in to comment.