[Plugin system] Move archives to dependency injection.

This commit is contained in:
2023-10-05 16:19:55 +01:00
parent e00af2a93f
commit e19cdd942a
3 changed files with 10 additions and 12 deletions

View File

@@ -109,16 +109,14 @@ public class PluginRegisterGenerator : ISourceGenerator
if(archives?.Count > 0)
{
sb.AppendLine(" public List<Type> GetAllArchivePlugins() => new()");
sb.AppendLine(" public void RegisterArchivePlugins(IServiceCollection services)");
sb.AppendLine(" {");
foreach(string plugin in archives)
sb.AppendLine($" typeof({plugin}),");
sb.AppendLine(" };");
sb.AppendLine($" services.AddTransient<IArchive, {plugin}>();");
sb.AppendLine(" }");
}
else
sb.AppendLine(" public List<Type> GetAllArchivePlugins() => null;");
sb.AppendLine(" public void RegisterArchivePlugins(IServiceCollection services) {}");
sb.AppendLine();

View File

@@ -100,12 +100,12 @@ sealed class FormatsCommand : Command
table.AddColumn(UI.Title_Filter);
foreach(KeyValuePair<string, IFilter> kvp in PluginRegister.Singleton.Filters)
foreach(IFilter filter in PluginRegister.Singleton.Filters.Values)
{
if(verbose)
table.AddRow(kvp.Value.Id.ToString(), Markup.Escape(kvp.Value.Name));
table.AddRow(filter.Id.ToString(), Markup.Escape(filter.Name));
else
table.AddRow(Markup.Escape(kvp.Value.Name));
table.AddRow(Markup.Escape(filter.Name));
}
AnsiConsole.Write(table);
@@ -256,9 +256,9 @@ sealed class FormatsCommand : Command
table.AddColumn("Archive format");
foreach(KeyValuePair<string, Type> kvp in plugins.Archives)
foreach(IArchive archive in plugins.Archives.Values)
{
if(Activator.CreateInstance(kvp.Value) is not IArchive archive)
if(archive is null)
continue;
if(verbose)