global using Microsoft.AspNetCore.Authorization; global using Microsoft.AspNetCore.Mvc; global using Microsoft.AspNetCore.SignalR; global using Microsoft.EntityFrameworkCore; global using Microsoft.IdentityModel.Tokens; global using qtc_api.Data; global using qtc_api.Dtos.Room; global using qtc_api.Dtos.User; global using qtc_api.Hubs; global using qtc_api.Models; global using qtc_api.Schema; global using qtc_api.Services.TokenService; global using qtc_api.Services.UserService; global using System.Text; using qtc_api.Services.BucketService; using qtc_api.Services.ContactService; using qtc_api.Services.CurrencyGamesService; using qtc_api.Services.EmailService; using qtc_api.Services.GameRoomService; using qtc_api.Services.RoomService; using qtc_api.Services.StoreService; using System.Text.Json; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddDbContext(); builder.Services.AddSignalR().AddHubOptions(options => { options.EnableDetailedErrors = true; }); builder.Services.AddStackExchangeRedisCache(options => { var redisConnectionString = Environment.GetEnvironmentVariable("REDIS_CONNECTIONSTRING"); if (redisConnectionString != null) options.Configuration = redisConnectionString; if (!builder.Environment.IsProduction()) options.InstanceName = "QtCNetServerDev_"; else options.InstanceName = "QtCNetServer_"; }); builder.Services.AddAuthentication().AddJwtBearer(); builder.Services.AddTransient(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(provider => GetServerConfig()); ServerConfig GetServerConfig() { if (!File.Exists("./Resources/ServerConfig.json")) throw new Exception("Server Config Doesn't Exist. Please Refer To The Repo For Examples."); else { try { var _jsonText = File.ReadAllText("./Resources/ServerConfig.json"); ServerConfig? _config = JsonSerializer.Deserialize(_jsonText); if (_config != null) return _config; else throw new Exception("Invalid Server Config. Please Refer To The Repo For Examples."); } catch (JsonException) { throw new Exception("Invalid Server Config. Please Refer To The Repo For Examples."); } } } builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(provider => provider.GetService()!); var app = builder.Build(); using var scope = app.Services.CreateScope(); await scope.ServiceProvider.GetRequiredService().Database.EnsureCreatedAsync(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.MapHub("/chat"); app.MapHub("/tttgame"); app.Run();