File tree 2 files changed +3
-4
lines changed
2 files changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,6 @@ This library contains these features:
60
60
## Limitations
61
61
62
62
This library contains these limitations:
63
- - The plugin loader is not thread-safe.
64
63
- There is no support for unload plugins.
65
64
66
65
## Why did I create this library?
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Collections . Concurrent ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Reflection ;
@@ -10,7 +11,7 @@ namespace CPlugin.Net;
10
11
/// </summary>
11
12
public static class PluginLoader
12
13
{
13
- private readonly static Dictionary < string , Assembly > s_assemblies = new ( ) ;
14
+ private readonly static ConcurrentDictionary < string , Assembly > s_assemblies = new ( ) ;
14
15
15
16
/// <summary>
16
17
/// Gets the plugin assemblies.
@@ -32,7 +33,6 @@ public static class PluginLoader
32
33
public static void Load ( CPluginConfigurationBase configuration )
33
34
{
34
35
ArgumentNullException . ThrowIfNull ( configuration ) ;
35
-
36
36
var assemblyFiles = configuration . GetPluginFiles ( ) ;
37
37
foreach ( string assemblyFile in assemblyFiles )
38
38
{
@@ -47,7 +47,7 @@ private static void LoadAssembly(string assemblyFile)
47
47
var loadContext = new PluginLoadContext ( assemblyFile ) ;
48
48
var assemblyName = AssemblyName . GetAssemblyName ( assemblyFile ) ;
49
49
var currentAssembly = loadContext . LoadFromAssemblyName ( assemblyName ) ;
50
- s_assemblies . Add ( assemblyFile , currentAssembly ) ;
50
+ s_assemblies . TryAdd ( assemblyFile , currentAssembly ) ;
51
51
PluginLogger . DefaultLogInformation ( currentAssembly . GetName ( ) . Name , currentAssembly . FullName ) ;
52
52
}
53
53
You can’t perform that action at this time.
0 commit comments