[Plugin system] Move checksums to dependency injection.

This commit is contained in:
2023-10-05 13:04:57 +01:00
parent 064f149107
commit 7df41de4af
10 changed files with 41 additions and 13 deletions

View File

@@ -100,6 +100,7 @@ public class PluginRegisterGenerator : ISourceGenerator
sb.AppendLine("using System;");
sb.AppendLine("using System.Collections.Generic;");
sb.AppendLine("using Aaru.CommonTypes.Interfaces;");
sb.AppendLine("using Microsoft.Extensions.DependencyInjection;");
sb.AppendLine();
sb.AppendLine($"namespace {@namespace};");
sb.AppendLine();
@@ -123,16 +124,14 @@ public class PluginRegisterGenerator : ISourceGenerator
if(checksums?.Count > 0)
{
sb.AppendLine(" public List<Type> GetAllChecksumPlugins() => new()");
sb.AppendLine(" public void RegisterChecksumPlugins(IServiceCollection services)");
sb.AppendLine(" {");
foreach(string plugin in checksums)
sb.AppendLine($" typeof({plugin}),");
sb.AppendLine(" };");
sb.AppendLine($" services.AddTransient<IChecksum, {plugin}>();");
sb.AppendLine(" }");
}
else
sb.AppendLine(" public List<Type> GetAllChecksumPlugins() => null;");
sb.AppendLine(" public void RegisterChecksumPlugins(IServiceCollection services) {}");
sb.AppendLine();