diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index 571039c88..332e27687 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting.WindowsServices; using NLog; +using Npgsql; using NzbDrone.Common.Composition.Extensions; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; @@ -55,6 +56,7 @@ namespace NzbDrone.Host Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var appMode = GetApplicationMode(startupContext); + var config = GetConfiguration(startupContext); switch (appMode) { @@ -83,12 +85,22 @@ namespace NzbDrone.Host // Utility mode default: { - new Container(rules => rules.WithNzbDroneRules()) - .AutoAddServices(ASSEMBLIES) - .AddNzbDroneLogger() - .AddStartupContext(startupContext) - .Resolve() - .Route(appMode); + new HostBuilder() + .UseServiceProviderFactory(new DryIocServiceProviderFactory(new Container(rules => rules.WithNzbDroneRules()))) + .ConfigureContainer(c => + { + c.AutoAddServices(Bootstrap.ASSEMBLIES) + .AddNzbDroneLogger() + .AddDatabase() + .AddStartupContext(startupContext) + .Resolve() + .Route(appMode); + }) + .ConfigureServices(services => + { + services.Configure(config.GetSection("Readarr:Postgres")); + }).Build(); + break; } } @@ -111,6 +123,7 @@ namespace NzbDrone.Host GC.Collect(); GC.WaitForPendingFinalizers(); SQLiteConnection.ClearAllPools(); + NpgsqlConnection.ClearAllPools(); } public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContext context)