-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
138 lines (119 loc) · 5.16 KB
/
Program.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using allmylinks;
using allmylinks.Abstractions;
using allmylinks.Extensions;
using allmylinks.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.DependencyInjection.Extensions;
using MudBlazor.Services;
using Radzen;
using Stl.DependencyInjection;
using Stl.Fusion;
using Stl.Fusion.Authentication;
using Stl.Fusion.Blazor;
using Stl.Fusion.Client;
using Stl.Fusion.Extensions;
using Stl.OS;
internal class Program
{
private static Task Main(string[] args)
{
if (OSInfo.Kind != OSKind.WebAssembly)
throw new ApplicationException("This app runs only in browser.");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddMudServices();
// builder.Services.AddControllers();
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
var DbDir = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "database"));
var DatabasePath = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "database"), "main.db");
builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<NotificationService>();
builder.Services.AddScoped<TooltipService>();
builder.Services.AddScoped<ContextMenuService>();
builder.Services.AddScoped<SideBarService>();
builder.Services.AddScoped<LayoutService>();
builder.Services.TryAddScoped<ClientAuthHelper>();
builder.Services.TryAddDocsViewServices();
try
{
builder.Services.AddDatabaseFeatures();
}
catch (Exception)
{
// ignore
}
builder.Services.AddScoped<PersonServices>();
builder.Services.AddCors(options =>
{
options.AddPolicy(name: "AllowGithub",
policy =>
{
policy.WithOrigins("https://github.com");
});
});
ConfigureServices(builder.Services, builder);
var host = builder.Build();
// host.UseHttpsRedirection();
// host.UseStaticFiles();
// host.UseRouting();
// builder.Services.Configure<ForwardedHeadersOptions>(options =>
// {
// options.ForwardedHeaders =
// ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
// });
host.Services.HostedServices().Start();
return host.RunAsync();
}
public static void ConfigureServices(IServiceCollection services, WebAssemblyHostBuilder builder)
{
builder.Logging.SetMinimumLevel(LogLevel.Warning);
var baseUri = new Uri(builder.HostEnvironment.BaseAddress);
var apiBaseUri = new Uri($"{baseUri}api/");
// Fusion
var fusion = services.AddFusion();
var fusionClient = fusion.AddRestEaseClient();
fusionClient.ConfigureWebSocketChannel(c => new()
{
BaseUri = baseUri,
LogLevel = LogLevel.Information,
MessageLogLevel = LogLevel.None,
});
fusionClient.ConfigureHttpClient((c, name, o) =>
{
var isFusionClient = (name ?? "").StartsWith("Stl.Fusion");
var clientBaseUri = isFusionClient ? baseUri : apiBaseUri;
o.HttpClientActions.Add(client => client.BaseAddress = clientBaseUri);
});
// // Fusion service clients
fusionClient.AddReplicaService<ICounterService, ICounterClientDef>();
fusionClient.AddClientService<IAuthBackend>();
// fusionClient.AddClientService<IAuth>();
fusionClient.AddClientService<ISessionResolver>();
// fusionClient.AddReplicaService<IWeatherForecastService, IWeatherForecastClientDef>();
// fusionClient.AddReplicaService<IChatService, IChatClientDef>();
fusion.AddComputeService<ISqlService, SqlService>();
ConfigureSharedServices(services);
}
public static void ConfigureSharedServices(IServiceCollection services)
{
// Other UI-related services
var fusion = services.AddFusion();
fusion.AddBlazorUIServices();
fusion.AddFusionTime();
fusion.AddBackendStatus<CustomBackendStatus>();
// We don't care about Sessions in this sample, but IBackendStatus
// service assumes it's there, so let's register a fake one
services.AddSingleton(new SessionFactory().CreateSession());
// Default update delay is set to min.
services.AddTransient<IUpdateDelayer>(_ => UpdateDelayer.MinDelay);
}
}