From 1494be68e4cb70618aa5b849db111566e2710d0c Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Sat, 25 May 2024 08:49:08 -0500 Subject: [PATCH 1/2] feat: Use ConcurrentDictionary type to provide thread safety --- src/Core/PluginLoader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); } From 952a86eff569d09aa1d2a7ad27b45f3cb40a8966 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Sat, 25 May 2024 08:50:28 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) 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?