-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathStartup.cs
83 lines (73 loc) · 2.9 KB
/
Startup.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
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Samples.HelloBlazorServer.Services;
using Stl.Fusion.Blazor;
using Stl.Fusion.Extensions;
using Stl.Fusion.UI;
namespace Samples.HelloBlazorServer;
public class Startup
{
private IConfiguration Cfg { get; }
private IWebHostEnvironment Env { get; }
private ILogger Log { get; set; } = NullLogger<Startup>.Instance;
public Startup(IConfiguration cfg, IWebHostEnvironment environment)
{
Cfg = cfg;
Env = environment;
}
public void ConfigureServices(IServiceCollection services)
{
// Logging
services.AddLogging(logging => {
logging.ClearProviders();
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Information);
if (Env.IsDevelopment()) {
logging.AddFilter("Microsoft", LogLevel.Warning);
logging.AddFilter("Microsoft.AspNetCore.Hosting", LogLevel.Information);
logging.AddFilter("Stl.Fusion.Operations", LogLevel.Information);
}
});
#pragma warning disable ASP0000
var tmpServices = services.BuildServiceProvider();
#pragma warning restore ASP0000
Log = tmpServices.GetRequiredService<ILogger<Startup>>();
// Fusion services
var fusion = services.AddFusion();
fusion.AddBlazor();
fusion.AddFusionTime(); // IFusionTime is one of built-in compute services you can use
fusion.AddService<CounterService>();
fusion.AddService<WeatherForecastService>();
fusion.AddService<ChatService>();
fusion.AddService<ChatBotService>();
// This is just to make sure ChatBotService.StartAsync is called on startup
services.AddHostedService(c => c.GetRequiredService<ChatBotService>());
// Default update delay is set to 0.1s
services.AddTransient<IUpdateDelayer>(c => new UpdateDelayer(c.UIActionTracker(), 0.1));
// ASP.NET Core / Blazor services
services.AddRazorPages();
services.AddServerSideBlazor(o => o.DetailedErrors = true);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
else {
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}