global using Microsoft.AspNetCore.Mvc; global using Microsoft.EntityFrameworkCore; global using Microsoft.AspNetCore.SignalR; global using Microsoft.AspNetCore.Authorization; global using qtc_api.Models; global using qtc_api.Schema; global using qtc_api.Data; global using qtc_api.Dtos.User; global using qtc_api.Dtos.Room; global using qtc_api.Services.UserService; global using Microsoft.IdentityModel.Tokens; global using System.Text; global using qtc_api.Services.TokenService; global using qtc_api.Hubs; using qtc_api.Services.RoomService; using qtc_api.Services.ContactService; using qtc_api.Services.CurrencyGamesService; using qtc_api.Services.GameRoomService; using qtc_api.Services.StoreService; using qtc_api.Services.EmailService; 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.AddEndpointsApiExplorer(); builder.Services.AddSignalR(); 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(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = builder.Configuration["Jwt:Issuer"], ValidAudience = builder.Configuration["Jwt:Audience"] }; var jwtKey = Environment.GetEnvironmentVariable("JWT_KEY"); if (jwtKey != null) options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)); else throw new Exception("Cannot Find Environment Variables 'JWT_KEY'. Please Check Environment."); }); builder.Services.AddTransient(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); 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.UseAuthorization(); app.MapControllers(); app.MapHub("/chat"); app.MapHub("/tttgame"); app.Run();