Do not save a reference to the startup config in ApplicationHost

This commit is contained in:
Mark Monteiro 2020-02-28 23:28:15 +01:00
parent a4e5a5ab31
commit 48f8118072
4 changed files with 17 additions and 23 deletions

View File

@ -328,8 +328,6 @@ namespace Emby.Server.Implementations
private IMediaSourceManager MediaSourceManager { get; set; } private IMediaSourceManager MediaSourceManager { get; set; }
private readonly IConfiguration _configuration;
/// <summary> /// <summary>
/// Gets the installation manager. /// Gets the installation manager.
/// </summary> /// </summary>
@ -367,11 +365,8 @@ namespace Emby.Server.Implementations
IStartupOptions options, IStartupOptions options,
IFileSystem fileSystem, IFileSystem fileSystem,
IImageEncoder imageEncoder, IImageEncoder imageEncoder,
INetworkManager networkManager, INetworkManager networkManager)
IConfiguration configuration)
{ {
_configuration = configuration;
XmlSerializer = new MyXmlSerializer(); XmlSerializer = new MyXmlSerializer();
NetworkManager = networkManager; NetworkManager = networkManager;
@ -587,7 +582,8 @@ namespace Emby.Server.Implementations
} }
} }
public async Task InitAsync(IServiceCollection serviceCollection) /// <inheritdoc/>
public async Task InitAsync(IServiceCollection serviceCollection, IConfiguration startupConfig)
{ {
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
@ -620,7 +616,7 @@ namespace Emby.Server.Implementations
DiscoverTypes(); DiscoverTypes();
await RegisterResources(serviceCollection).ConfigureAwait(false); await RegisterResources(serviceCollection, startupConfig).ConfigureAwait(false);
ContentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath; ContentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
if (string.IsNullOrEmpty(ContentRoot)) if (string.IsNullOrEmpty(ContentRoot))
@ -659,7 +655,7 @@ namespace Emby.Server.Implementations
/// <summary> /// <summary>
/// Registers resources that classes will depend on /// Registers resources that classes will depend on
/// </summary> /// </summary>
protected async Task RegisterResources(IServiceCollection serviceCollection) protected async Task RegisterResources(IServiceCollection serviceCollection, IConfiguration startupConfig)
{ {
serviceCollection.AddMemoryCache(); serviceCollection.AddMemoryCache();
@ -762,7 +758,7 @@ namespace Emby.Server.Implementations
ProcessFactory, ProcessFactory,
LocalizationManager, LocalizationManager,
() => SubtitleEncoder, () => SubtitleEncoder,
_configuration, startupConfig,
StartupOptions.FFmpegPath); StartupOptions.FFmpegPath);
serviceCollection.AddSingleton(MediaEncoder); serviceCollection.AddSingleton(MediaEncoder);
@ -784,7 +780,7 @@ namespace Emby.Server.Implementations
this, this,
LoggerFactory.CreateLogger<HttpListenerHost>(), LoggerFactory.CreateLogger<HttpListenerHost>(),
ServerConfigurationManager, ServerConfigurationManager,
_configuration, startupConfig,
NetworkManager, NetworkManager,
JsonSerializer, JsonSerializer,
XmlSerializer, XmlSerializer,

View File

@ -23,23 +23,20 @@ namespace Jellyfin.Server
/// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param> /// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
/// <param name="imageEncoder">The <see cref="IImageEncoder" /> to be used by the <see cref="CoreAppHost" />.</param> /// <param name="imageEncoder">The <see cref="IImageEncoder" /> to be used by the <see cref="CoreAppHost" />.</param>
/// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param> /// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param>
/// <param name="configuration">The <see cref="IConfiguration" /> to be used by the <see cref="CoreAppHost" />.</param>
public CoreAppHost( public CoreAppHost(
ServerApplicationPaths applicationPaths, ServerApplicationPaths applicationPaths,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
StartupOptions options, StartupOptions options,
IFileSystem fileSystem, IFileSystem fileSystem,
IImageEncoder imageEncoder, IImageEncoder imageEncoder,
INetworkManager networkManager, INetworkManager networkManager)
IConfiguration configuration)
: base( : base(
applicationPaths, applicationPaths,
loggerFactory, loggerFactory,
options, options,
fileSystem, fileSystem,
imageEncoder, imageEncoder,
networkManager, networkManager)
configuration)
{ {
} }

View File

@ -103,10 +103,10 @@ namespace Jellyfin.Server
// Create an instance of the application configuration to use for application startup // Create an instance of the application configuration to use for application startup
await InitLoggingConfigFile(appPaths).ConfigureAwait(false); await InitLoggingConfigFile(appPaths).ConfigureAwait(false);
IConfiguration appConfig = CreateAppConfiguration(appPaths); IConfiguration startupConfig = CreateAppConfiguration(appPaths);
// Initialize logging framework // Initialize logging framework
InitializeLoggingFramework(appConfig, appPaths); InitializeLoggingFramework(startupConfig, appPaths);
_logger = _loggerFactory.CreateLogger("Main"); _logger = _loggerFactory.CreateLogger("Main");
// Log uncaught exceptions to the logging instead of std error // Log uncaught exceptions to the logging instead of std error
@ -171,12 +171,11 @@ namespace Jellyfin.Server
options, options,
new ManagedFileSystem(_loggerFactory.CreateLogger<ManagedFileSystem>(), appPaths), new ManagedFileSystem(_loggerFactory.CreateLogger<ManagedFileSystem>(), appPaths),
GetImageEncoder(appPaths), GetImageEncoder(appPaths),
new NetworkManager(_loggerFactory.CreateLogger<NetworkManager>()), new NetworkManager(_loggerFactory.CreateLogger<NetworkManager>()));
appConfig);
try try
{ {
ServiceCollection serviceCollection = new ServiceCollection(); ServiceCollection serviceCollection = new ServiceCollection();
await appHost.InitAsync(serviceCollection).ConfigureAwait(false); await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false);
var webHost = CreateWebHostBuilder(appHost, serviceCollection, appPaths).Build(); var webHost = CreateWebHostBuilder(appHost, serviceCollection, appPaths).Build();

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Updates; using MediaBrowser.Model.Updates;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common namespace MediaBrowser.Common
@ -121,11 +122,12 @@ namespace MediaBrowser.Common
void RemovePlugin(IPlugin plugin); void RemovePlugin(IPlugin plugin);
/// <summary> /// <summary>
/// Inits this instance. /// Initializes this instance.
/// </summary> /// </summary>
/// <param name="serviceCollection">The service collection.</param> /// <param name="serviceCollection">The service collection.</param>
/// <param name="startupConfig">The configuration to use for initialization.</param>
/// <returns>A task.</returns> /// <returns>A task.</returns>
Task InitAsync(IServiceCollection serviceCollection); Task InitAsync(IServiceCollection serviceCollection, IConfiguration startupConfig);
/// <summary> /// <summary>
/// Creates the instance. /// Creates the instance.