diff --git a/README.md b/README.md index 464df00..3076626 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ This library contains these features: ## Limitations This library contains these limitations: -- The plugin loader is not thread-safe. - There is no support for unload plugins. ## Why did I create this library? diff --git a/src/Core/PluginLoader.cs b/src/Core/PluginLoader.cs index 5c002ef..c5cc223 100644 --- a/src/Core/PluginLoader.cs +++ b/src/Core/PluginLoader.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -10,7 +11,7 @@ namespace CPlugin.Net; /// public static class PluginLoader { - private readonly static Dictionary s_assemblies = new(); + private readonly static ConcurrentDictionary s_assemblies = new(); /// /// Gets the plugin assemblies. @@ -32,7 +33,6 @@ public static class PluginLoader public static void Load(CPluginConfigurationBase configuration) { ArgumentNullException.ThrowIfNull(configuration); - var assemblyFiles = configuration.GetPluginFiles(); foreach (string assemblyFile in assemblyFiles) { @@ -47,7 +47,7 @@ private static void LoadAssembly(string assemblyFile) var loadContext = new PluginLoadContext(assemblyFile); var assemblyName = AssemblyName.GetAssemblyName(assemblyFile); var currentAssembly = loadContext.LoadFromAssemblyName(assemblyName); - s_assemblies.Add(assemblyFile, currentAssembly); + s_assemblies.TryAdd(assemblyFile, currentAssembly); PluginLogger.DefaultLogInformation(currentAssembly.GetName().Name, currentAssembly.FullName); }