-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorComponentClientModule.cs
More file actions
84 lines (73 loc) · 3.2 KB
/
RazorComponentClientModule.cs
File metadata and controls
84 lines (73 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Services;
using Microsoft.Extensions.DependencyInjection;
using Modulight.Modules.Client.RazorComponents.UI;
using Modulight.Modules.Hosting;
namespace Modulight.Modules.Client.RazorComponents
{
/// <summary>
/// Specifies the contract for razor component modules.
/// </summary>
public interface IRazorComponentClientModule : IModule
{
/// <summary>
/// Get module icon.
/// </summary>
RenderFragment? Icon { get; }
/// <summary>
/// Get the manifest.
/// </summary>
RazorComponentClientModuleManifest RazorComponentClientModuleManifest { get; }
}
/// <summary>
/// Basic implement for <see cref="IRazorComponentClientModule"/>.
/// </summary>
[ModuleDependency(typeof(RazorComponentClientCoreModule))]
public abstract class RazorComponentClientModule : Module, IRazorComponentClientModule
{
readonly Lazy<RazorComponentClientModuleManifest> _manifest;
/// <summary>
/// Create the instance.
/// </summary>
/// <param name="host"></param>
protected RazorComponentClientModule(IModuleHost host) : base(host)
{
Collection = host.GetRazorComponentClientModuleCollection();
_manifest = new Lazy<RazorComponentClientModuleManifest>(() => Collection.GetManifest(GetType()));
}
/// <inheritdoc/>
public virtual RenderFragment? Icon => null;
/// <inheritdoc/>
public RazorComponentClientModuleManifest RazorComponentClientModuleManifest => _manifest.Value;
/// <summary>
/// Get collection of razor component modules.
/// </summary>
protected IRazorComponentClientModuleCollection Collection { get; }
/// <summary>
/// Get page provider.
/// </summary>
/// <returns></returns>
protected IPageProvider? GetPageProvider() => this.GetPageProvider(Host);
}
[Module(Author = "StardustDL", Description = "Provide services for razor component client modules.", Url = "https://github.com/StardustDL/modulight")]
[ModuleService(typeof(RazorComponentClientModuleCollection), ServiceType = typeof(IRazorComponentClientModuleCollection), Lifetime = ServiceLifetime.Singleton)]
[ModuleService(typeof(JSModuleProvider<>), ServiceType = typeof(IJSModuleProvider<>))]
[ModuleService(typeof(LazyAssemblyLoader))]
[ModuleService(typeof(ModuleUILoader))]
class RazorComponentClientCoreModule : Module
{
public RazorComponentClientCoreModule(IModuleHost host, IRazorComponentClientModuleCollection collection) : base(host)
{
Collection = collection;
}
public IRazorComponentClientModuleCollection Collection { get; }
public override async Task Initialize(CancellationToken cancellationToken = default)
{
if (Environment.OSVersion.Platform is PlatformID.Other)
{
await Collection.LoadResources(cancellationToken: cancellationToken).ConfigureAwait(false);
}
await base.Initialize(cancellationToken).ConfigureAwait(false);
}
}
}