Cleaning plugin requirements

This commit is contained in:
Zoe Roux 2021-05-04 15:16:59 +02:00
parent 3e8dbc84a8
commit 709e12191d
3 changed files with 16 additions and 24 deletions

View File

@ -1,20 +0,0 @@
using System;
namespace Kyoo.Models.Exceptions
{
/// <summary>
/// An exception raised when a plugin requires dependencies that can't be found with the current configuration.
/// </summary>
[Serializable]
public class MissingDependencyException : Exception
{
/// <summary>
/// Create a new <see cref="MissingDependencyException"/> with a custom message
/// </summary>
/// <param name="plugin">The name of the plugin that can't be loaded.</param>
/// <param name="dependency">The name of the missing dependency.</param>
public MissingDependencyException(string plugin, string dependency)
: base($"No {dependency} are available in Kyoo but the plugin {plugin} requires it.")
{}
}
}

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using Kyoo.Models.Exceptions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -106,8 +105,8 @@ namespace Kyoo.Controllers
if (missing == null)
return true;
Exception error = new MissingDependencyException(plugin.Name, missing.Name);
_logger.LogCritical(error, "A plugin's dependency could not be met");
_logger.LogCritical("No {Dependency} available in Kyoo but the plugin {Plugin} requires it",
missing.Name, plugin.Name);
return false;
}));

View File

@ -48,7 +48,20 @@ namespace Kyoo
};
/// <inheritdoc />
public ICollection<Type> Requires => ArraySegment<Type>.Empty;
public ICollection<Type> Requires => new []
{
typeof(ILibraryRepository),
typeof(ILibraryItemRepository),
typeof(ICollectionRepository),
typeof(IShowRepository),
typeof(ISeasonRepository),
typeof(IEpisodeRepository),
typeof(ITrackRepository),
typeof(IPeopleRepository),
typeof(IStudioRepository),
typeof(IGenreRepository),
typeof(IProviderRepository)
};
/// <inheritdoc />
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)