using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Server.Kestrel.Core; using sodoff.Configuration; using sodoff.Middleware; using sodoff.Model; using sodoff.Services; using sodoff.Utils; using System.Xml; using System.Net; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.Configure(builder.Configuration.GetSection("AssetServer")); builder.Services.Configure(builder.Configuration.GetSection("ApiServer")); builder.Services.AddControllers(options => { options.OutputFormatters.Add(new XmlSerializerOutputFormatter(new XmlWriterSettings() { OmitXmlDeclaration = false })); options.OutputFormatters.RemoveType(); options.Filters.Add(); }); builder.Services.AddDbContext(); // create Modding Service singleton here ... do this before start http server to avoid serve invalid assets list builder.Services.AddSingleton(new ModdingService()); // other singletons will be created at first use ... builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHostedService(provider => provider.GetService()); bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue("Enabled"); string assetIP = builder.Configuration.GetSection("AssetServer").GetValue("ListenIP"); int assetPort = builder.Configuration.GetSection("AssetServer").GetValue("Port"); if (assetServer) builder.Services.Configure(options => { if (String.IsNullOrEmpty(assetIP) || assetIP == "*") options.ListenAnyIP(assetPort); else options.Listen(IPAddress.Parse(assetIP), assetPort); }); var app = builder.Build(); using var scope = app.Services.CreateScope(); scope.ServiceProvider.GetRequiredService().Database.EnsureCreated(); // Configure the HTTP request pipeline. if (assetServer) app.UseMiddleware(); app.UseAuthorization(); app.MapControllers(); app.Run();