diff --git a/Interfaces/IPluginRegister.cs b/Interfaces/IPluginRegister.cs index 7e35cb1..f3ddf8f 100644 --- a/Interfaces/IPluginRegister.cs +++ b/Interfaces/IPluginRegister.cs @@ -36,8 +36,6 @@ // Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ -using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; @@ -107,7 +105,9 @@ public interface IPluginRegister /// Service collection void RegisterArchivePlugins(IServiceCollection services); - /// Gets all byte addressable plugins - /// List of byte addressable plugins - List GetAllByteAddressablePlugins(); + /// + /// Registers all byte addressable media image plugins in the provided service collection + /// + /// Service collection + void RegisterByteAddressablePlugins(IServiceCollection services); } \ No newline at end of file diff --git a/PluginRegister.cs b/PluginRegister.cs index e561a3d..1ec417a 100644 --- a/PluginRegister.cs +++ b/PluginRegister.cs @@ -33,7 +33,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using Microsoft.Extensions.DependencyInjection; @@ -44,13 +43,24 @@ public class PluginRegister { static PluginRegister _instance; - /// List of byte addressable image plugins - public readonly SortedDictionary ByteAddressableImages; IServiceProvider _serviceProvider; IServiceCollection _services; - PluginRegister() => ByteAddressableImages = new SortedDictionary(); + PluginRegister() {} + + /// List of byte addressable image plugins + public SortedDictionary ByteAddressableImages + { + get + { + SortedDictionary byteAddressableImages = new(); + foreach(IByteAddressableImage plugin in _serviceProvider.GetServices()) + byteAddressableImages[plugin.Name.ToLower()] = plugin; + + return byteAddressableImages; + } + } /// List of writable media image plugins public SortedDictionary WritableImages @@ -230,13 +240,7 @@ public class PluginRegister pluginRegister.RegisterWritableFloppyImagePlugins(_services); pluginRegister.RegisterWritableImagePlugins(_services); pluginRegister.RegisterArchivePlugins(_services); - - foreach(Type type in pluginRegister.GetAllByteAddressablePlugins() ?? Enumerable.Empty()) - { - if(Activator.CreateInstance(type) is IByteAddressableImage plugin && - !ByteAddressableImages.ContainsKey(plugin.Name.ToLower())) - ByteAddressableImages.Add(plugin.Name.ToLower(), type); - } + pluginRegister.RegisterByteAddressablePlugins(_services); } /// Gets the filter that allows to read the specified path