Reordered services startup (#558)
* Reordered services startup * Removed unnecessary comment * Made startup service required * Marked other services as required * Removed unnecessary ! for null --------- Co-authored-by: Alex <clodanSPT@hotmail.com> Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com>
This commit is contained in:
@@ -64,7 +64,6 @@ public static class Program
|
||||
|
||||
builder.Services.AddSingleton(builder);
|
||||
builder.Services.AddSingleton<IReadOnlyList<SptMod>>(loadedMods);
|
||||
builder.Services.AddHostedService<SptServerBackgroundService>();
|
||||
// Configure Kestrel options
|
||||
ConfigureKestrel(builder);
|
||||
|
||||
@@ -74,9 +73,9 @@ public static class Program
|
||||
ConfigureWebApp(app);
|
||||
|
||||
// In case of exceptions we snatch a Server logger
|
||||
var serverExceptionLogger = app.Services.GetService<ILoggerFactory>()!.CreateLogger("Server");
|
||||
var serverExceptionLogger = app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Server");
|
||||
// We need any logger instance to use as a finalizer when the app closes
|
||||
var loggerFinalizer = app.Services.GetService<ISptLogger<App>>()!;
|
||||
var loggerFinalizer = app.Services.GetRequiredService<ISptLogger<App>>();
|
||||
try
|
||||
{
|
||||
// Handle edge cases where reverse proxies might pass X-Forwarded-For, use this as the actual IP address
|
||||
@@ -86,6 +85,8 @@ public static class Program
|
||||
|
||||
SetConsoleOutputMode();
|
||||
|
||||
await app.Services.GetRequiredService<SptServerStartupService>().Startup();
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -111,7 +112,7 @@ public static class Program
|
||||
app.Use(
|
||||
async (HttpContext context, RequestDelegate _) =>
|
||||
{
|
||||
await context.RequestServices.GetService<HttpServer>()!.HandleRequest(context);
|
||||
await context.RequestServices.GetRequiredService<HttpServer>().HandleRequest(context);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -122,8 +123,8 @@ public static class Program
|
||||
(_, options) =>
|
||||
{
|
||||
// This method is not expected to be async so we need to wait for the Task instead of using await keyword
|
||||
options.ApplicationServices.GetService<OnWebAppBuildModLoader>()!.OnLoad().Wait();
|
||||
var httpConfig = options.ApplicationServices.GetService<ConfigServer>()?.GetConfig<HttpConfig>()!;
|
||||
options.ApplicationServices.GetRequiredService<OnWebAppBuildModLoader>().OnLoad().Wait();
|
||||
var httpConfig = options.ApplicationServices.GetRequiredService<ConfigServer>().GetConfig<HttpConfig>();
|
||||
|
||||
// Probe the http ip and port to see if its being used, this method will throw an exception and crash
|
||||
// the server if the IP/Port combination is already in use
|
||||
@@ -138,7 +139,7 @@ public static class Program
|
||||
listener?.Stop();
|
||||
}
|
||||
|
||||
var certHelper = options.ApplicationServices.GetService<CertificateHelper>()!;
|
||||
var certHelper = options.ApplicationServices.GetRequiredService<CertificateHelper>();
|
||||
options.Listen(
|
||||
IPAddress.Parse(httpConfig.Ip),
|
||||
httpConfig.Port,
|
||||
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
using System.Runtime;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Loaders;
|
||||
using SPTarkov.Server.Core.Models.Spt.Mod;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
namespace SPTarkov.Server.Services;
|
||||
|
||||
public class SptServerBackgroundService(IReadOnlyList<SptMod> loadedMods, BundleLoader bundleLoader, App app) : BackgroundService
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class SptServerStartupService(IReadOnlyList<SptMod> loadedMods, BundleLoader bundleLoader, App app)
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
public async Task Startup()
|
||||
{
|
||||
if (ProgramStatics.MODS())
|
||||
{
|
||||
Reference in New Issue
Block a user