File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ This library contains these features:
6060## Limitations
6161
6262This library contains these limitations:
63- - The plugin loader is not thread-safe.
6463- There is no support for unload plugins.
6564
6665## Why did I create this library?
Original file line number Diff line number Diff line change 11using System ;
2+ using System . Collections . Concurrent ;
23using System . Collections . Generic ;
34using System . Linq ;
45using System . Reflection ;
@@ -10,7 +11,7 @@ namespace CPlugin.Net;
1011/// </summary>
1112public static class PluginLoader
1213{
13- private readonly static Dictionary < string , Assembly > s_assemblies = new ( ) ;
14+ private readonly static ConcurrentDictionary < string , Assembly > s_assemblies = new ( ) ;
1415
1516 /// <summary>
1617 /// Gets the plugin assemblies.
@@ -32,7 +33,6 @@ public static class PluginLoader
3233 public static void Load ( CPluginConfigurationBase configuration )
3334 {
3435 ArgumentNullException . ThrowIfNull ( configuration ) ;
35-
3636 var assemblyFiles = configuration . GetPluginFiles ( ) ;
3737 foreach ( string assemblyFile in assemblyFiles )
3838 {
@@ -47,7 +47,7 @@ private static void LoadAssembly(string assemblyFile)
4747 var loadContext = new PluginLoadContext ( assemblyFile ) ;
4848 var assemblyName = AssemblyName . GetAssemblyName ( assemblyFile ) ;
4949 var currentAssembly = loadContext . LoadFromAssemblyName ( assemblyName ) ;
50- s_assemblies . Add ( assemblyFile , currentAssembly ) ;
50+ s_assemblies . TryAdd ( assemblyFile , currentAssembly ) ;
5151 PluginLogger . DefaultLogInformation ( currentAssembly . GetName ( ) . Name , currentAssembly . FullName ) ;
5252 }
5353
You can’t perform that action at this time.
0 commit comments