From 7837f702589935886935754ee6136329d47d025d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 13 Sep 2021 21:49:05 -0500 Subject: add SoulseekClient to DI --- src/slskd/Startup.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index c8c96584..d147efef 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -37,12 +37,12 @@ namespace slskd using slskd.Cryptography; using slskd.Integrations.FTP; using slskd.Integrations.Pushbullet; - using slskd.Management; using slskd.Messaging; using slskd.Peer; using slskd.Search; using slskd.Transfer; using slskd.Validation; + using Soulseek; /// /// ASP.NET Startup. @@ -199,6 +199,16 @@ namespace slskd services.AddHttpClient(); + // add a partially configured instance of SoulseekClient. the Application instance will + // complete configuration at startup. + services.AddSingleton(_ => + new SoulseekClient(options: new SoulseekClientOptions(minimumDiagnosticLevel: OptionsAtStartup.Soulseek.DiagnosticLevel))); + + // add Application to DI as well as a hosted service so that other services can + // access instance methods + services.AddSingleton(); + services.AddHostedService(p => p.GetRequiredService()); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -208,16 +218,12 @@ namespace slskd services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - - services.AddTransient(); - - services.AddSingleton(); - services.AddHostedService(p => p.GetRequiredService()); } /// @@ -265,7 +271,7 @@ namespace slskd FileServerOptions fileServerOptions = default; - if (!Directory.Exists(ContentPath)) + if (!System.IO.Directory.Exists(ContentPath)) { logger.Warning($"Static content disabled; cannot find content path '{ContentPath}'"); } @@ -330,7 +336,7 @@ namespace slskd // finally, hit the fileserver again. if the path was modified to return the index above, the index document will be // returned. otherwise it will throw a final 404 back to the client. - if (Directory.Exists(ContentPath)) + if (System.IO.Directory.Exists(ContentPath)) { app.UseFileServer(fileServerOptions); } -- cgit v1.2.3