Skip to content

Commit 1bd513c

Browse files
authored
Enable inline documentation (#44)
* Inline XML Documentation * Only error for nullable related warnings * - fix small bug of incorrect cache of manifest paths - small improvements to lazy component (loading, error and required) * fix OnBeforeLoadAsync
1 parent d2e3257 commit 1bd513c

File tree

25 files changed

+198
-74
lines changed

25 files changed

+198
-74
lines changed

demo/WasmHost/Pages/Counter.razor

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
1010

1111
<Lazy Name="SimpleComponent" OnBeforeLoadAsync="Delay(500, 2500)">
12-
<LazyPlaceholder />
12+
<Loading>
13+
<LazyPlaceholder />
14+
</Loading>
15+
<Error>
16+
<h2>Component loading errored...</h2>
17+
</Error>
1318
</Lazy>
1419

15-
<Lazy Name="NamedComponent" OnBeforeLoadAsync="Delay(500, 2500)">
16-
<LazyPlaceholder />
20+
<Lazy Name="NamedComponent" Required="true" OnBeforeLoadAsync="Delay(500, 2500)">
21+
<Loading>
22+
<LazyPlaceholder />
23+
</Loading>
1724
</Lazy>
1825

1926
@code {

nuget/BlazorLazyLoading.Components/BlazorLazyLoading.Components.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<RazorLangVersion>3.0</RazorLangVersion>
6+
<LangVersion>8.0</LangVersion>
7+
<Nullable>enable</Nullable>
8+
<WarningsAsErrors>nullable</WarningsAsErrors>
9+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
610
</PropertyGroup>
711

812
<PropertyGroup>

nuget/BlazorLazyLoading.Server/BlazorLazyLoading.Server.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<OutputType>Library</OutputType>
66
<LangVersion>8.0</LangVersion>
77
<Nullable>enable</Nullable>
8-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<WarningsAsErrors>nullable</WarningsAsErrors>
9+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
910
</PropertyGroup>
1011

1112
<ItemGroup>

nuget/BlazorLazyLoading.Server/StartupExtensions.cs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@
1111

1212
namespace BlazorLazyLoading.Server
1313
{
14+
/// <summary>
15+
/// Server startup extensions for BlazorLazyLoading
16+
/// </summary>
1417
public static class BLLServerStartupExtensions
1518
{
19+
/// <summary>
20+
/// Registers BlazorLazyLoading services
21+
/// </summary>
1622
public static IServiceCollection AddLazyLoading(
1723
this IServiceCollection services,
1824
LazyLoadingOptions options)
1925
{
20-
services.AddScoped<IAssemblyLoader, AssemblyLoader>();
26+
if (options.UseAssemblyIsolation)
27+
{
28+
services.AddScoped<IAssemblyLoader, AssemblyLoader>();
29+
}
30+
else
31+
{
32+
services.AddSingleton<IAssemblyLoader, AssemblyLoader>();
33+
}
34+
2135
services.AddSingleton<IAssemblyLoadContextFactory, DisposableAssemblyLoadContextFactory>();
22-
services.AddSingleton<IAssemblyDataLocator, AssemblyDataLocator>();
2336
services.AddSingleton<IAssemblyDataProvider, AssemblyDataProvider>();
37+
services.AddSingleton(typeof(IAssemblyDataLocator), options.AssemblyDataLocator ?? typeof(AssemblyDataLocator));
2438

2539
services.AddSingleton<IContentFileReader>(
2640
p =>
@@ -38,6 +52,9 @@ public static IServiceCollection AddLazyLoading(
3852
return services;
3953
}
4054

55+
/// <summary>
56+
/// Configures the host to use BlazorLazyLoading
57+
/// </summary>
4158
public static void UseLazyLoading(
4259
this IApplicationBuilder app)
4360
{
@@ -53,13 +70,26 @@ public static void UseLazyLoading(
5370
}
5471
}
5572

73+
/// <summary>
74+
/// BlazorLazyLoading options
75+
/// </summary>
5676
public sealed class LazyLoadingOptions
5777
{
5878
/// <summary>
59-
/// Specifies a list of Module Names (hints) to:
60-
/// - Download DLLs from them
61-
/// - Use their manifest to locate lazy resources
79+
/// Specifies a list of Module Names (hints) to download DLLs from them and use their manifest to locate lazy resources
6280
/// </summary>
6381
public IEnumerable<string> ModuleHints { get; set; } = Array.Empty<string>();
82+
83+
/// <summary>
84+
/// <br>Configures assembly isolation level. Do NOT set this to 'false' unless you want to share 'static' fields between users.</br>
85+
/// <br>Keeping this enabled ensures that the server can be scaled horizontally.</br>
86+
/// <br>default: true</br>
87+
/// </summary>
88+
public bool UseAssemblyIsolation { get; set; } = true;
89+
90+
/// <summary>
91+
/// Configures a custom AssemblyDataLocator. The type must implement IAssemblyDataLocator.
92+
/// </summary>
93+
public Type? AssemblyDataLocator { get; set; } = null;
6494
}
6595
}

nuget/BlazorLazyLoading.Wasm/BlazorLazyLoading.Wasm.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>8.0</LangVersion>
66
<Nullable>enable</Nullable>
7-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<WarningsAsErrors>nullable</WarningsAsErrors>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
89
</PropertyGroup>
910

1011
<ItemGroup>

nuget/BlazorLazyLoading.Wasm/StartupExtensions.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
namespace BlazorLazyLoading.Wasm
99
{
10+
/// <summary>
11+
/// WebAssembly startup extensions for BlazorLazyLoading
12+
/// </summary>
1013
public static class BLLWasmStartupExtensions
1114
{
15+
/// <summary>
16+
/// Registers BlazorLazyLoading services
17+
/// </summary>
1218
public static IServiceCollection AddLazyLoading(
1319
this IServiceCollection services,
1420
LazyLoadingOptions options)
1521
{
1622
services.AddSingleton<IAssemblyLoader, AssemblyLoader>();
1723
services.AddSingleton<IAssemblyLoadContextFactory, AppDomainAssemblyLoadContextFactory>();
18-
services.AddSingleton<IAssemblyDataLocator, AssemblyDataLocator>();
24+
services.AddSingleton(typeof(IAssemblyDataLocator), options.AssemblyDataLocator ?? typeof(AssemblyDataLocator));
1925
services.AddSingleton<IContentFileReader, NetworkContentFileReader>();
2026
services.AddSingleton<IAssemblyDataProvider, AssemblyDataProvider>();
2127

@@ -29,13 +35,19 @@ public static IServiceCollection AddLazyLoading(
2935
}
3036
}
3137

38+
/// <summary>
39+
/// BlazorLazyLoading options
40+
/// </summary>
3241
public sealed class LazyLoadingOptions
3342
{
3443
/// <summary>
35-
/// Specifies a list of Module Names (hints) to:
36-
/// - Download DLLs from them
37-
/// - Use their manifest to locate lazy resources
44+
/// Specifies a list of Module Names (hints) to download DLLs from them and use their manifest to locate lazy resources
3845
/// </summary>
3946
public IEnumerable<string> ModuleHints { get; set; } = Array.Empty<string>();
47+
48+
/// <summary>
49+
/// Configures a custom AssemblyDataLocator. The type must implement IAssemblyDataLocator.
50+
/// </summary>
51+
public Type? AssemblyDataLocator { get; set; } = null;
4052
}
4153
}

src/AssemblyLoader.Server/AssemblyLoader.Server.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<OutputType>Library</OutputType>
66
<LangVersion>8.0</LangVersion>
77
<Nullable>enable</Nullable>
8-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<WarningsAsErrors>nullable</WarningsAsErrors>
9+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
910
</PropertyGroup>
1011

1112
<PropertyGroup>

src/AssemblyLoader.Wasm/AssemblyLoader.Wasm.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>8.0</LangVersion>
66
<Nullable>enable</Nullable>
7-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<WarningsAsErrors>nullable</WarningsAsErrors>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
89
</PropertyGroup>
910

1011
<PropertyGroup>

src/AssemblyLoader.Wasm/Services/AppDomainAssemblyLoadContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace BlazorLazyLoading.Wasm.Services
1111
{
12-
public sealed class AppDomainAssemblyLoadContext : IAssemblyLoadContext
12+
internal sealed class AppDomainAssemblyLoadContext : IAssemblyLoadContext
1313
{
1414
private readonly object _domainLock = new object();
1515
private readonly AppDomain _baseDomain;

src/AssemblyLoader/Abstractions/IAssemblyDataLocator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
namespace BlazorLazyLoading.Abstractions
66
{
7+
/// <summary>
8+
/// Locates assembly DLLs based on context and hints
9+
/// </summary>
710
public interface IAssemblyDataLocator
811
{
912
/// <summary>
10-
/// Returns a list of possible paths where the assembly data is
13+
/// Returns a list of possible paths to look for the assembly data (dll)
1114
/// </summary>
1215
public IEnumerable<string> GetFindPaths(AssemblyName assemblyName, AssemblyLoaderContext context);
1316
}

src/AssemblyLoader/AssemblyLoader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>8.0</LangVersion>
66
<Nullable>enable</Nullable>
7-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<WarningsAsErrors>nullable</WarningsAsErrors>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
89
</PropertyGroup>
910

1011
<PropertyGroup>

src/AssemblyLoader/Comparers/AssemblyByNameAndVersionComparer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Reflection;
3-
using BlazorLazyLoading.Helpers;
43

54
namespace BlazorLazyLoading.Comparers
65
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace BlazorLazyLoading.Extensions
6+
{
7+
public static class EnumerableExtensions
8+
{
9+
public static IEnumerable<T> NotNull<T>(
10+
this IEnumerable<T?> source)
11+
where T : class
12+
{
13+
return source.Where(i => i != null).Cast<T>();
14+
}
15+
16+
public static IEnumerable<T> DistinctBy<T, TOut>(
17+
this IEnumerable<T> source,
18+
Func<T, TOut> selector)
19+
{
20+
return source
21+
.GroupBy(m => selector(m))
22+
.Select(g => g.First());
23+
}
24+
}
25+
}

src/AssemblyLoader/Helpers/HashCode.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/AssemblyLoader/Models/AssemblyData.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
namespace BlazorLazyLoading.Models
22
{
3+
/// <summary>
4+
/// Contains the data required to load an assembly
5+
/// </summary>
36
public sealed class AssemblyData
47
{
8+
/// <summary>Bytes from the DLL</summary>
59
public readonly byte[] DllBytes;
10+
11+
/// <summary>Bytes from the PDB</summary>
612
public readonly byte[]? PdbBytes;
713

14+
/// Constructs AssemblyData
815
public AssemblyData(
916
byte[] dllBytes,
1017
byte[]? pdbBytes)

src/AssemblyLoader/Models/AssemblyLoaderContext.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33

44
namespace BlazorLazyLoading.Models
55
{
6+
/// <summary>
7+
/// Describes the tree of loaded assembly dependencies
8+
/// </summary>
69
public sealed class AssemblyLoaderContext
710
{
11+
/// <summary>
12+
/// Assembly Name
13+
/// </summary>
814
public readonly AssemblyName AssemblyName;
915

16+
/// Parent Node
1017
public readonly AssemblyLoaderContext? Parent = null;
18+
19+
/// Children Nodes
1120
public readonly List<AssemblyLoaderContext> Children = new List<AssemblyLoaderContext>();
1221

22+
/// Constructs the AssemblyLoaderContext
1323
public AssemblyLoaderContext(AssemblyName name)
1424
{
1525
AssemblyName = name;
@@ -21,6 +31,9 @@ private AssemblyLoaderContext(AssemblyName name, AssemblyLoaderContext parent)
2131
AssemblyName = name;
2232
}
2333

34+
/// <summary>
35+
/// Creates a new scope for the current AssemblyLoaderContext
36+
/// </summary>
2437
public AssemblyLoaderContext NewScope(AssemblyName name)
2538
{
2639
var scope = new AssemblyLoaderContext(name, this);

src/AssemblyLoader/Services/AssemblyDataLocator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55

66
namespace BlazorLazyLoading.Services
77
{
8+
/// <summary>
9+
/// Locates assembly DLLs based on context and hints
10+
/// </summary>
811
public sealed class AssemblyDataLocator : IAssemblyDataLocator
912
{
1013
private readonly ILazyModuleHintsProvider _lazyModuleNamesProvider;
1114

15+
/// <inheritdoc/>
1216
public AssemblyDataLocator(
1317
ILazyModuleHintsProvider lazyModuleProvider)
1418
{
1519
_lazyModuleNamesProvider = lazyModuleProvider;
1620
}
1721

22+
/// <inheritdoc/>
1823
public IEnumerable<string> GetFindPaths(
1924
AssemblyName assemblyName,
2025
AssemblyLoaderContext context)

0 commit comments

Comments
 (0)