mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #9078 from barronpm/migrate-to-ihost
This commit is contained in:
commit
12786db0cc
@ -41,7 +41,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.2" />
|
||||||
<PackageReference Include="prometheus-net" Version="7.0.0" />
|
<PackageReference Include="prometheus-net" Version="7.0.0" />
|
||||||
<PackageReference Include="prometheus-net.AspNetCore" Version="7.0.0" />
|
<PackageReference Include="prometheus-net.AspNetCore" Version="7.0.0" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
|
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
||||||
|
@ -6,7 +6,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -21,7 +20,6 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
@ -186,20 +184,22 @@ namespace Jellyfin.Server
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var serviceCollection = new ServiceCollection();
|
var host = Host.CreateDefaultBuilder()
|
||||||
appHost.Init(serviceCollection);
|
.ConfigureServices(services => appHost.Init(services))
|
||||||
|
.ConfigureWebHostDefaults(webHostBuilder => webHostBuilder.ConfigureWebHostBuilder(appHost, startupConfig, appPaths))
|
||||||
|
.ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(options, appPaths, startupConfig))
|
||||||
|
.UseSerilog()
|
||||||
|
.Build();
|
||||||
|
|
||||||
var webHost = new WebHostBuilder().ConfigureWebHostBuilder(appHost, serviceCollection, options, startupConfig, appPaths).Build();
|
// Re-use the host service provider in the app host since ASP.NET doesn't allow a custom service collection.
|
||||||
|
appHost.ServiceProvider = host.Services;
|
||||||
// Re-use the web host service provider in the app host since ASP.NET doesn't allow a custom service collection.
|
|
||||||
appHost.ServiceProvider = webHost.Services;
|
|
||||||
|
|
||||||
await appHost.InitializeServices().ConfigureAwait(false);
|
await appHost.InitializeServices().ConfigureAwait(false);
|
||||||
Migrations.MigrationRunner.Run(appHost, _loggerFactory);
|
Migrations.MigrationRunner.Run(appHost, _loggerFactory);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await webHost.StartAsync(_tokenSource.Token).ConfigureAwait(false);
|
await host.StartAsync(_tokenSource.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (!OperatingSystem.IsWindows() && startupConfig.UseUnixSocket())
|
if (!OperatingSystem.IsWindows() && startupConfig.UseUnixSocket())
|
||||||
{
|
{
|
||||||
@ -284,16 +284,12 @@ namespace Jellyfin.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder">The builder to configure.</param>
|
/// <param name="builder">The builder to configure.</param>
|
||||||
/// <param name="appHost">The application host.</param>
|
/// <param name="appHost">The application host.</param>
|
||||||
/// <param name="serviceCollection">The application service collection.</param>
|
|
||||||
/// <param name="commandLineOpts">The command line options passed to the application.</param>
|
|
||||||
/// <param name="startupConfig">The application configuration.</param>
|
/// <param name="startupConfig">The application configuration.</param>
|
||||||
/// <param name="appPaths">The application paths.</param>
|
/// <param name="appPaths">The application paths.</param>
|
||||||
/// <returns>The configured web host builder.</returns>
|
/// <returns>The configured web host builder.</returns>
|
||||||
public static IWebHostBuilder ConfigureWebHostBuilder(
|
public static IWebHostBuilder ConfigureWebHostBuilder(
|
||||||
this IWebHostBuilder builder,
|
this IWebHostBuilder builder,
|
||||||
ApplicationHost appHost,
|
CoreAppHost appHost,
|
||||||
IServiceCollection serviceCollection,
|
|
||||||
StartupOptions commandLineOpts,
|
|
||||||
IConfiguration startupConfig,
|
IConfiguration startupConfig,
|
||||||
IApplicationPaths appPaths)
|
IApplicationPaths appPaths)
|
||||||
{
|
{
|
||||||
@ -349,14 +345,7 @@ namespace Jellyfin.Server
|
|||||||
_logger.LogInformation("Kestrel listening to unix socket {SocketPath}", socketPath);
|
_logger.LogInformation("Kestrel listening to unix socket {SocketPath}", socketPath);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(commandLineOpts, appPaths, startupConfig))
|
.UseStartup(_ => new Startup(appHost));
|
||||||
.UseSerilog()
|
|
||||||
.ConfigureServices(services =>
|
|
||||||
{
|
|
||||||
// Merge the external ServiceCollection into ASP.NET DI
|
|
||||||
services.Add(serviceCollection);
|
|
||||||
})
|
|
||||||
.UseStartup<Startup>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -35,20 +35,17 @@ namespace Jellyfin.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _serverConfigurationManager;
|
|
||||||
private readonly IServerApplicationHost _serverApplicationHost;
|
private readonly IServerApplicationHost _serverApplicationHost;
|
||||||
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Startup" /> class.
|
/// Initializes a new instance of the <see cref="Startup" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serverConfigurationManager">The server configuration manager.</param>
|
/// <param name="appHost">The server application host.</param>
|
||||||
/// <param name="serverApplicationHost">The server application host.</param>
|
public Startup(CoreAppHost appHost)
|
||||||
public Startup(
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IServerApplicationHost serverApplicationHost)
|
|
||||||
{
|
{
|
||||||
_serverConfigurationManager = serverConfigurationManager;
|
_serverApplicationHost = appHost;
|
||||||
_serverApplicationHost = serverApplicationHost;
|
_serverConfigurationManager = appHost.ConfigurationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -87,8 +84,7 @@ namespace Jellyfin.Server
|
|||||||
RequestHeaderEncodingSelector = (_, _) => Encoding.UTF8
|
RequestHeaderEncodingSelector = (_, _) => Encoding.UTF8
|
||||||
};
|
};
|
||||||
|
|
||||||
services
|
services.AddHttpClient(NamedClient.Default, c =>
|
||||||
.AddHttpClient(NamedClient.Default, c =>
|
|
||||||
{
|
{
|
||||||
c.DefaultRequestHeaders.UserAgent.Add(productHeader);
|
c.DefaultRequestHeaders.UserAgent.Add(productHeader);
|
||||||
c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
|
c.DefaultRequestHeaders.Accept.Add(acceptJsonHeader);
|
||||||
@ -208,7 +204,7 @@ namespace Jellyfin.Server
|
|||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
if (_serverConfigurationManager.Configuration.EnableMetrics)
|
if (_serverConfigurationManager.Configuration.EnableMetrics)
|
||||||
{
|
{
|
||||||
endpoints.MapMetrics("/metrics");
|
endpoints.MapMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoints.MapHealthChecks("/health");
|
endpoints.MapHealthChecks("/health");
|
||||||
|
@ -8,6 +8,7 @@ using MediaBrowser.Common;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc.Testing;
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@ -78,11 +79,17 @@ namespace Jellyfin.Server.Integration.Tests
|
|||||||
commandLineOpts,
|
commandLineOpts,
|
||||||
startupConfig);
|
startupConfig);
|
||||||
_disposableComponents.Add(appHost);
|
_disposableComponents.Add(appHost);
|
||||||
var serviceCollection = new ServiceCollection();
|
|
||||||
appHost.Init(serviceCollection);
|
|
||||||
|
|
||||||
// Configure the web host builder
|
builder.ConfigureServices(services => appHost.Init(services))
|
||||||
Program.ConfigureWebHostBuilder(builder, appHost, serviceCollection, commandLineOpts, startupConfig, appPaths);
|
.ConfigureWebHostBuilder(appHost, startupConfig, appPaths)
|
||||||
|
.ConfigureAppConfiguration((context, builder) =>
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.SetBasePath(appPaths.ConfigurationDirectoryPath)
|
||||||
|
.AddInMemoryCollection(ConfigurationOptions.DefaultConfiguration)
|
||||||
|
.AddEnvironmentVariables("JELLYFIN_")
|
||||||
|
.AddInMemoryCollection(commandLineOpts.ConvertToConfig());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user