Skip to content

Commit

Permalink
feat: lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
aguacongas committed Oct 28, 2020
1 parent 5fd6532 commit b632e78
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 47 deletions.
3 changes: 1 addition & 2 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<!-- dayly -->
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="aspnet-extensions" value="https://dotnetfeed.blob.core.windows.net/aspnet-extensions/index.json" />
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0-rc.2.20475.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="5.0.0-preview.6.20312.15" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0-rc.2.20475.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.2.20475.17" PrivateAssets="all" />
</ItemGroup>

Expand Down Expand Up @@ -66,6 +66,7 @@
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.Culture.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProvider.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.Identities.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.Identity.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.Import.dll" />
<BlazorWebAssemblyLazyLoad Include="Aguacongas.TheIdServer.BlazorApp.Pages.Keys.dll" />
Expand Down
15 changes: 11 additions & 4 deletions src/Aguacongas.TheIdServer.BlazorApp/App.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class App
"Api",
"ApiScope",
"Client",
"Culture",
"ExternalProvider",
"Identities",
"Identity",
Expand All @@ -31,19 +32,24 @@ public partial class App
private Task OnNavigateAsync(NavigationContext args)
{
_logger.LogDebug($"OnNavigateAsync {args.Path}");
var path = args.Path;
if (path.StartsWith("protectresource"))
var path = args.Path.Split("/")[0];
if (path == "protectresource")
{
return LoadAssemblyAsync("Aguacongas.TheIdServer.BlazorApp.Pages.Api.dll");
}

var pageKind = _pageKindList.FirstOrDefault(k => path.StartsWith($"{k.ToLower()}s"));
if (path == "identityresource")
{
return LoadAssemblyAsync("Aguacongas.TheIdServer.BlazorApp.Pages.Identity.dll");
}

var pageKind = _pageKindList.FirstOrDefault(k => path == $"{k.ToLower()}s");
if (pageKind != null)
{
return LoadAssemblyAsync($"Aguacongas.TheIdServer.BlazorApp.Pages.{pageKind}s.dll");
}

pageKind = _pageKindList.FirstOrDefault(k => path.StartsWith($"{k.ToLower()}"));
pageKind = _pageKindList.FirstOrDefault(k => path == k.ToLower());
if (pageKind != null)
{
return LoadAssemblyAsync($"Aguacongas.TheIdServer.BlazorApp.Pages.{pageKind}.dll");
Expand All @@ -54,6 +60,7 @@ private Task OnNavigateAsync(NavigationContext args)

private async Task LoadAssemblyAsync(string assemblyName)
{
_logger.LogDebug($"LoadAssemblyAsync {assemblyName}");
var assemblies = await _assemblyLoader.LoadAssembliesAsync(
new[] { assemblyName }).ConfigureAwait(false);
_lazyLoadedAssemblies.AddRange(assemblies.Where(a => !_lazyLoadedAssemblies.Any(l => l.FullName == a.FullName)));
Expand Down
4 changes: 2 additions & 2 deletions src/Aguacongas.TheIdServer.BlazorApp/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="scopes">
<NavLink class="nav-link" href="apiscopes">
<span class="oi oi-shield" aria-hidden="true"></span> @Localizer["Scopes"]
</NavLink>
</li>
Expand All @@ -48,7 +48,7 @@
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="providers">
<NavLink class="nav-link" href="externalproviders">
<span class="oi oi-cloud-upload" aria-hidden="true"></span> @Localizer["Providers"]
</NavLink>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<ItemGroup>
<PackageReference Include="Aguacongas.AspNetCore.Authentication" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0-rc.2.20475.5" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.8.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ private static IValidator GetValidatorForModel(object entity, object model, IStr
return (IValidator)Activator.CreateInstance(entityValidatorType, entity, resource.ResourceKind, localizer);
}
var abstractValidatorType = typeof(AbstractValidator<>).MakeGenericType(model.GetType());
var modelValidatorType = Assembly.GetExecutingAssembly()
.GetTypes().FirstOrDefault(t => t.IsSubclassOf(abstractValidatorType));
if (modelValidatorType == null)
var assemby = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetTypes().Any(t => t.IsSubclassOf(abstractValidatorType)));
if (assemby == null)
{
return null;
}

var modelValidatorType = assemby.GetTypes().First(t => t.IsSubclassOf(abstractValidatorType));

var modelValidatorInstance = (IValidator)Activator.CreateInstance(modelValidatorType, entity, localizer);
return modelValidatorInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Entity = Aguacongas.IdentityServer.Store.Entity;
Expand Down Expand Up @@ -66,7 +67,9 @@ private static TOptions Deserialize(string options, Type optionsType)

private static Type GetOptionsType(Entity.ExternalProvider externalProvider)
{
return Type.GetType($"{typeof(RemoteAuthenticationOptions).Namespace}.{externalProvider.KindName}Options");
var typeName = $"{typeof(RemoteAuthenticationOptions).Namespace}.{externalProvider.KindName}Options";
var assembly = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetType(typeName) != null);
return assembly.GetType(typeName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/scopes"
@page "/apiscopes"
@inherits EntitiesModel<Entity.ApiScope>

<div class="row sticky-top bg-light">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ else
</ul>
</div>
<FluentValidationValidator />
<div class="w-100"></div>
<ValidationSummary class="col" />
</div>
<div class="entity-details">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/providers"
@page "/externalproviders"
@inherits EntitiesModel<Entity.ExternalProvider>

<div class="row sticky-top bg-light">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.2.20475.17" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.2.20475.5" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rtm.20512.8" />
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
</ItemGroup>
Expand Down

0 comments on commit b632e78

Please sign in to comment.