|
| 1 | +using DemoServer; |
1 | 2 | using IntelliTect.AspNetCore.SignalR.SqlServer; |
2 | | -using Microsoft.AspNetCore.Hosting; |
3 | | -using Microsoft.Extensions.Configuration; |
4 | | -using Microsoft.Extensions.Hosting; |
5 | | -using Microsoft.Extensions.Logging; |
6 | | -using System; |
7 | | -using System.Collections.Generic; |
8 | | -using System.Linq; |
9 | | -using System.Threading.Tasks; |
10 | | - |
11 | | -namespace DemoServer |
| 3 | +using Microsoft.AspNetCore.SignalR; |
| 4 | + |
| 5 | +var builder = WebApplication.CreateBuilder(args); |
| 6 | + |
| 7 | +// Configure app configuration |
| 8 | +builder.Configuration |
| 9 | + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) |
| 10 | + .AddJsonFile("appsettings.localhost.json", optional: true, reloadOnChange: true) |
| 11 | + .AddEnvironmentVariables(); |
| 12 | + |
| 13 | +// Configure logging |
| 14 | +builder.Logging.AddSimpleConsole(options => |
12 | 15 | { |
13 | | - public static class Program |
| 16 | + options.TimestampFormat = "hh:mm:ss "; |
| 17 | + options.SingleLine = false; |
| 18 | +}); |
| 19 | + |
| 20 | +// Configure services |
| 21 | +string connectionString = builder.Configuration.GetConnectionString("Default")!; |
| 22 | + |
| 23 | +builder.Services.AddSingleton<IUserIdProvider, UserIdProvider>(); |
| 24 | +builder.Services.AddRazorPages(); |
| 25 | +builder.Services.AddSignalR() |
| 26 | + .AddSqlServer(o => |
14 | 27 | { |
15 | | - public static void Main(string[] args) |
16 | | - { |
17 | | - CreateHostBuilder(args).Build().Run(); |
18 | | - } |
19 | | - |
20 | | - public static IHostBuilder CreateHostBuilder(string[] args) => |
21 | | - Host.CreateDefaultBuilder(args) |
22 | | - .ConfigureWebHostDefaults(webBuilder => |
23 | | - { |
24 | | - webBuilder.UseStartup<Startup>() |
25 | | - .ConfigureAppConfiguration((builder, config) => config |
26 | | - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) |
27 | | - .AddJsonFile("appsettings.localhost.json", optional: true, reloadOnChange: true) |
28 | | - .AddEnvironmentVariables() |
29 | | - ) |
30 | | - .ConfigureLogging(builder => |
31 | | - { |
32 | | - builder.AddSimpleConsole(options => |
33 | | - { |
34 | | - options.TimestampFormat = "hh:mm:ss "; |
35 | | - options.SingleLine = false; |
36 | | - }); |
37 | | - }); |
38 | | - }); |
39 | | - } |
| 28 | + o.ConnectionString = connectionString; |
| 29 | + o.AutoEnableServiceBroker = true; |
| 30 | + o.TableSlugGenerator = hubType => hubType.Name; |
| 31 | + o.TableCount = 1; |
| 32 | + o.SchemaName = "SignalRCore"; |
| 33 | + }); |
| 34 | + |
| 35 | +builder.Services.AddOptions<SqlServerOptions>().Configure<IConfiguration>((o, config) => |
| 36 | +{ |
| 37 | + o.ConnectionString = connectionString; |
| 38 | +}); |
| 39 | + |
| 40 | +// Build the app |
| 41 | +var app = builder.Build(); |
| 42 | + |
| 43 | +// Configure middleware |
| 44 | +if (app.Environment.IsDevelopment()) |
| 45 | +{ |
| 46 | + app.UseDeveloperExceptionPage(); |
| 47 | +} |
| 48 | +else |
| 49 | +{ |
| 50 | + app.UseExceptionHandler("/Error"); |
| 51 | + app.UseHsts(); |
40 | 52 | } |
| 53 | + |
| 54 | +app.UseHttpsRedirection(); |
| 55 | +app.UseStaticFiles(); |
| 56 | +app.UseRouting(); |
| 57 | +app.UseAuthorization(); |
| 58 | + |
| 59 | +app.MapRazorPages(); |
| 60 | +app.MapHub<ChatHubA>("/chatHubA"); |
| 61 | +app.MapHub<ChatHubB>("/chatHubB"); |
| 62 | + |
| 63 | +app.Run(); |
0 commit comments