-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloModule.cs
69 lines (61 loc) · 2.16 KB
/
HelloModule.cs
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
using Delights.Modules.Hello.GraphQL;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Modulight.Modules;
using Modulight.Modules.Client.RazorComponents;
using Modulight.Modules.Client.RazorComponents.UI;
using Modulight.Modules.Hosting;
using StardustDL.RazorComponents.MaterialDesignIcons;
namespace Delights.Modules.Hello
{
public static class ModuleExtensions
{
public static IModuleHostBuilder AddHelloModule(this IModuleHostBuilder builder, Action<ModuleOption, IServiceProvider>? configureOptions = null)
{
builder.AddModule<HelloModule>();
if (configureOptions is not null)
{
builder.ConfigureOptions(configureOptions);
}
return builder;
}
}
[Module(Url = SharedManifest.Url, Author = SharedManifest.Author, Description = SharedManifest.Description)]
[ModuleStartup(typeof(Startup))]
[ModulePageProvider(typeof(MPageProvider))]
[ModuleService(typeof(ModuleService))]
[ModuleUIResource(UIResourceType.Assembly, "Delights.Modules.Hello.UI")]
[ModuleDependency(typeof(MaterialDesignIconModule))]
public class HelloModule : RazorComponentClientModule
{
public HelloModule(IModuleHost host) : base(host)
{
}
public override RenderFragment Icon => Fragments.Icon;
}
[ModulePageRootPath("hello")]
class MPageProvider : PageProvider
{
}
class Startup : ModuleStartup
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddHelloClient().ConfigureHttpClient((sp, client) =>
{
var option = sp.GetRequiredService<IOptions<ModuleOption>>().Value;
client.BaseAddress = new Uri(option.GraphQLEndpoint.TrimEnd('/') + $"/Hello");
});
base.ConfigureServices(services);
}
}
public class ModuleService
{
public HelloClient GraphQLClient { get; }
public ModuleService(HelloClient graphQLClient)
{
GraphQLClient = graphQLClient;
}
}
}