using System;
using System.Collections.Generic;
using System.Linq;
using Autofac;
using Kyoo.Abstractions;
using Kyoo.Abstractions.Controllers;
using Kyoo.Authentication;
using Kyoo.Core.Controllers;
using Kyoo.Core.Models.Options;
using Kyoo.Core.Tasks;
using Kyoo.Postgresql;
using Kyoo.SqLite;
using Kyoo.TheMovieDb;
using Kyoo.TheTvdb;
using Kyoo.Utils;
using Kyoo.WebApp;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Kyoo.Core
{
///
/// The Startup class is used to configure the AspNet's webhost.
///
public class PluginsStartup
{
///
/// A plugin manager used to load plugins and allow them to configure services / asp net.
///
private readonly IPluginManager _plugins;
///
/// The configuration used to register and so on for plugin's specified types.
///
private readonly IConfiguration _configuration;
///
/// Created from the DI container, those services are needed to load information and instantiate plugins.s
///
/// The plugin manager to use to load new plugins and configure the host.
///
/// The configuration used to register and so on for plugin's specified types.
///
public PluginsStartup(IPluginManager plugins, IConfiguration configuration)
{
_plugins = plugins;
_configuration = configuration;
_plugins.LoadPlugins(
typeof(CoreModule),
typeof(WebAppModule),
typeof(AuthenticationModule),
typeof(PostgresModule),
typeof(SqLiteModule),
typeof(PluginTvdb),
typeof(PluginTmdb)
);
}
///
/// Configure the services context via the .
///
/// The service collection to fill.
public void ConfigureServices(IServiceCollection services)
{
foreach (IPlugin plugin in _plugins.GetAllPlugins())
plugin.Configure(services);
IEnumerable> configTypes = _plugins.GetAllPlugins()
.SelectMany(x => x.Configuration)
.Where(x => x.Value != null);
foreach ((string path, Type type) in configTypes)
{
Utility.RunGenericMethod