144 lines
4.0 KiB
C#
144 lines
4.0 KiB
C#
using ApexCharts;
|
|
using Fluxor;
|
|
using Fluxor.Blazor.Web.ReduxDevTools;
|
|
using Koogle.Application;
|
|
using Koogle.Application.Games;
|
|
using Koogle.Application.Games.DeathBox;
|
|
using Koogle.Application.Games.Shit;
|
|
using Koogle.Application.Games.Training;
|
|
using Koogle.Infrastructure;
|
|
using Koogle.Infrastructure.Data;
|
|
using Koogle.Infrastructure.Security;
|
|
using Koogle.Web.Components;
|
|
using Koogle.Web.Hubs;
|
|
using Koogle.Web.Services;
|
|
using Koogle.Web.Store.AuthState;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Components.Server;
|
|
using MudBlazor.Services;
|
|
using System.Reflection;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
// Infrastructure Layer (DbContext, Repositories, CurrentUserService, Authorization)
|
|
builder.Services.AddInfrastructure(builder.Configuration);
|
|
|
|
// Application Layer (Services, AutoMapper, Validators)
|
|
builder.Services.AddApplication();
|
|
|
|
// Game Types
|
|
builder.Services.AddGameType<TrainingGameDefinition, TrainingGameLogicService>();
|
|
builder.Services.AddGameType<ShitGameDefinition, ShitGameLogicService>();
|
|
builder.Services.AddGameType<DeathBoxGameDefinition, DeathBoxGameLogicService>();
|
|
|
|
// SignalR for real-time game updates
|
|
builder.Services.AddSignalR();
|
|
builder.Services.AddScoped<GameHubService>();
|
|
|
|
// FluentValidation
|
|
//builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
|
|
// Fluxor State Management
|
|
builder.Services.AddFluxor(options =>
|
|
{
|
|
options.UseRouting();
|
|
options.ScanAssemblies(typeof(Program).Assembly);
|
|
#if DEBUG
|
|
options.UseReduxDevTools();
|
|
#endif
|
|
});
|
|
builder.Services.AddScoped<AuthEffects>();
|
|
|
|
builder.Services.AddHttpContextAccessor();
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
// https://dev.to/masanori_msl/blazor-server-signin-with-custom-user-2e74
|
|
builder.Services.AddScoped<IHostEnvironmentAuthenticationStateProvider>(sp =>
|
|
(ServerAuthenticationStateProvider)sp.GetRequiredService<AuthenticationStateProvider>()
|
|
);
|
|
|
|
|
|
builder.Services.AddMudServices();
|
|
|
|
|
|
// ApexCharts - https://github.com/apexcharts/Blazor-ApexCharts
|
|
builder.Services.AddApexCharts(e =>
|
|
{
|
|
e.GlobalOptions = new ApexChartBaseOptions
|
|
{
|
|
Debug = true,
|
|
Theme = new Theme { Palette = PaletteType.Palette6 }
|
|
};
|
|
});
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// 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.MapControllers();
|
|
app.UseAntiforgery();
|
|
|
|
// Serve club-media from /home/data in production Linux (Azure App Service)
|
|
if (!app.Environment.IsDevelopment() && OperatingSystem.IsLinux())
|
|
{
|
|
var mediaPath = "/home/data/club-media";
|
|
if (!Directory.Exists(mediaPath))
|
|
{
|
|
Directory.CreateDirectory(mediaPath);
|
|
}
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(mediaPath),
|
|
RequestPath = "/club-media"
|
|
});
|
|
}
|
|
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
// SignalR Hub endpoint
|
|
app.MapHub<GameHub>("/gamehub");
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
await IdentityRoleSeeder.SeedAsync(scope.ServiceProvider);
|
|
|
|
// Initialize game types
|
|
var registry = scope.ServiceProvider.GetRequiredService<GameDefinitionRegistry>();
|
|
var initializers = scope.ServiceProvider.GetServices<IGameTypeInitializer>();
|
|
foreach (var initializer in initializers)
|
|
{
|
|
initializer.Initialize(registry);
|
|
}
|
|
}
|
|
await BootstrapSeeder.SeedAsync(app.Services, app.Configuration, app.Environment);
|
|
await BootstrapSeeder.SeedTriggersAsync(app.Services);
|
|
await DemoSeeder.SeedAsync(app.Services, app.Configuration, app.Environment);
|
|
|
|
|
|
app.Run();
|