diff --git a/Kyoo.Common/Controllers/IFileSystem.cs b/Kyoo.Common/Controllers/IFileSystem.cs
index 92e951b7..f443254f 100644
--- a/Kyoo.Common/Controllers/IFileSystem.cs
+++ b/Kyoo.Common/Controllers/IFileSystem.cs
@@ -2,25 +2,11 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using JetBrains.Annotations;
+using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Controllers
{
- ///
- /// A class wrapping a value that will be set after the completion of the task it is related to.
- ///
- ///
- /// This class replace the use of an out parameter on a task since tasks and out can't be combined.
- ///
- /// The type of the value
- public class AsyncRef
- {
- ///
- /// The value that will be set before the completion of the task.
- ///
- public T Value { get; set; }
- }
-
///
/// A service to abstract the file system to allow custom file systems (like distant file systems or external providers)
///
diff --git a/Kyoo.Common/Controllers/ITask.cs b/Kyoo.Common/Controllers/ITask.cs
index e8d07000..4d764fc7 100644
--- a/Kyoo.Common/Controllers/ITask.cs
+++ b/Kyoo.Common/Controllers/ITask.cs
@@ -55,7 +55,7 @@ namespace Kyoo.Controllers
/// A new task parameter.
public static TaskParameter Create(string name, string description)
{
- return new()
+ return new TaskParameter
{
Name = name,
Description = description,
@@ -72,7 +72,7 @@ namespace Kyoo.Controllers
/// A new task parameter.
public static TaskParameter CreateRequired(string name, string description)
{
- return new()
+ return new TaskParameter
{
Name = name,
Description = description,
diff --git a/Kyoo.Common/Models/AsyncRef.cs b/Kyoo.Common/Models/AsyncRef.cs
new file mode 100644
index 00000000..98738ac6
--- /dev/null
+++ b/Kyoo.Common/Models/AsyncRef.cs
@@ -0,0 +1,17 @@
+namespace Kyoo.Models
+{
+ ///
+ /// A class wrapping a value that will be set after the completion of the task it is related to.
+ ///
+ ///
+ /// This class replace the use of an out parameter on a task since tasks and out can't be combined.
+ ///
+ /// The type of the value
+ public class AsyncRef
+ {
+ ///
+ /// The value that will be set before the completion of the task.
+ ///
+ public T Value { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Kyoo/Controllers/FileSystems/HttpFileSystem.cs b/Kyoo/Controllers/FileSystems/HttpFileSystem.cs
index c7954db8..99155f62 100644
--- a/Kyoo/Controllers/FileSystems/HttpFileSystem.cs
+++ b/Kyoo/Controllers/FileSystems/HttpFileSystem.cs
@@ -5,6 +5,7 @@ using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Kyoo.Common.Models.Attributes;
+using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Controllers
diff --git a/Kyoo/Controllers/PluginManager.cs b/Kyoo/Controllers/PluginManager.cs
index 46185f16..646c644d 100644
--- a/Kyoo/Controllers/PluginManager.cs
+++ b/Kyoo/Controllers/PluginManager.cs
@@ -26,7 +26,7 @@ namespace Kyoo.Controllers
///
/// The configuration to get the plugin's directory.
///
- private readonly IOptionsMonitor _options;
+ private readonly IOptions _options;
///
/// The logger used by this class.
///
@@ -44,7 +44,7 @@ namespace Kyoo.Controllers
/// The configuration instance, to get the plugin's directory path.
/// The logger used by this class.
public PluginManager(IServiceProvider provider,
- IOptionsMonitor options,
+ IOptions options,
ILogger logger)
{
_provider = provider;
@@ -106,7 +106,7 @@ namespace Kyoo.Controllers
///
public void LoadPlugins(ICollection plugins)
{
- string pluginFolder = _options.CurrentValue.PluginPath;
+ string pluginFolder = _options.Value.PluginPath;
if (!Directory.Exists(pluginFolder))
Directory.CreateDirectory(pluginFolder);
diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs
index f1adfb40..509ae5f6 100644
--- a/Kyoo/Program.cs
+++ b/Kyoo/Program.cs
@@ -1,13 +1,13 @@
using System;
+using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
-using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Kyoo
@@ -32,7 +32,7 @@ namespace Kyoo
if (!File.Exists("./settings.json"))
File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "settings.json"), "settings.json");
- IWebHostBuilder builder = CreateWebHostBuilder(args);
+ IHostBuilder builder = CreateWebHostBuilder(args);
bool? debug = Environment.GetEnvironmentVariable("ENVIRONMENT")?.ToLowerInvariant() switch
{
@@ -83,40 +83,67 @@ namespace Kyoo
.AddCommandLine(args);
}
+ ///
+ /// Configure the logging.
+ ///
+ /// The host context that contains the configuration
+ /// The logger builder to configure.
+ private static void _ConfigureLogging(HostBuilderContext context, ILoggingBuilder builder)
+ {
+ builder.AddConfiguration(context.Configuration.GetSection("logging"))
+ .AddSimpleConsole(x =>
+ {
+ x.TimestampFormat = "[hh:mm:ss] ";
+ })
+ .AddDebug()
+ .AddEventSourceLogger();
+ }
+
///
/// Create a a web host
///
/// Command line parameters that can be handled by kestrel
+ ///
+ /// An action to configure the logging. If it is null, will be used.
+ ///
/// A new web host instance
- private static IWebHostBuilder CreateWebHostBuilder(string[] args)
+ public static IHostBuilder CreateWebHostBuilder(string[] args,
+ Action loggingConfiguration = null)
{
IConfiguration configuration = SetupConfig(new ConfigurationBuilder(), args).Build();
+ loggingConfiguration ??= _ConfigureLogging;
- return new WebHostBuilder()
- .ConfigureServices(x =>
- {
- AutofacServiceProviderFactory factory = new();
- x.Replace(ServiceDescriptor.Singleton>(factory));
- })
+ return new HostBuilder()
+ .UseServiceProviderFactory(new AutofacServiceProviderFactory())
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
- .UseConfiguration(configuration)
.ConfigureAppConfiguration(x => SetupConfig(x, args))
- .ConfigureLogging((context, builder) =>
- {
- builder.AddConfiguration(context.Configuration.GetSection("logging"))
- .AddSimpleConsole(x =>
- {
- x.TimestampFormat = "[hh:mm:ss] ";
- })
- .AddDebug()
- .AddEventSourceLogger();
- })
+ .ConfigureLogging(loggingConfiguration)
.ConfigureServices(x => x.AddRouting())
- .UseKestrel(options => { options.AddServerHeader = false; })
- .UseIIS()
- .UseIISIntegration()
- .UseUrls(configuration.GetValue("basics:url"))
- .UseStartup();
+ .ConfigureWebHost(x => x
+ .UseKestrel(options => { options.AddServerHeader = false; })
+ .UseIIS()
+ .UseIISIntegration()
+ .UseUrls(configuration.GetValue("basics:url"))
+ .UseStartup(host => new Startup(
+ host.HostingEnvironment,
+ host.Configuration,
+ LoggerFactory.Create(builder => loggingConfiguration(host.ToGenericHost(), builder)))
+ )
+ );
+ }
+
+ ///
+ /// Convert an to a .
+ ///
+ /// The to convert.
+ /// A containing the same properties.
+ private static HostBuilderContext ToGenericHost(this WebHostBuilderContext host)
+ {
+ return new HostBuilderContext(new Dictionary