1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT license.
3
3
4
- using System ;
5
4
using System . Collections . Generic ;
6
- using System . IO ;
7
- using System . Runtime . Loader ;
5
+ using System . Reflection ;
8
6
using Garnet . common ;
7
+ using Garnet . resources ;
9
8
using Microsoft . Extensions . Logging ;
10
9
11
10
namespace Garnet . server . Resp
12
11
{
13
12
internal class RespCommandDataCommon
14
13
{
15
- /// <summary>
16
- /// Path to Garnet.resources.dll, where command data is found
17
- /// </summary>
18
- private static readonly string ResourcesAssemblyPath = Path . Combine ( AppContext . BaseDirectory , @"Garnet.resources.dll" ) ;
19
-
20
- /// <summary>
21
- /// Synchronize loading and unloading of resources assembly
22
- /// </summary>
23
- private static readonly object ResourcesAssemblyLock = new object ( ) ;
24
-
25
14
/// <summary>
26
15
/// Safely imports commands data from embedded resource in dynamically loaded/unloaded assembly
27
16
/// </summary>
@@ -33,32 +22,15 @@ internal class RespCommandDataCommon
33
22
internal static bool TryImportRespCommandsData < TData > ( string path ,
34
23
out IReadOnlyDictionary < string , TData > commandsData , ILogger logger = null ) where TData : class , IRespCommandData < TData >
35
24
{
36
- lock ( ResourcesAssemblyLock )
37
- {
38
- // Create a new unloadable assembly load context
39
- var assemblyLoadContext = new AssemblyLoadContext ( null , true ) ;
40
-
41
- try
42
- {
43
- // Load the assembly within the context and import the data
44
- var assembly = assemblyLoadContext . LoadFromAssemblyPath ( ResourcesAssemblyPath ) ;
45
-
46
- var streamProvider = StreamProviderFactory . GetStreamProvider ( FileLocationType . EmbeddedResource , null , assembly ) ;
47
- var commandsDocsProvider = RespCommandsDataProviderFactory . GetRespCommandsDataProvider < TData > ( ) ;
25
+ // Garnet.resources assembly, where command data is found
26
+ var resourcesAssembly = Assembly . GetAssembly ( typeof ( ResourceUtils ) ) ;
48
27
49
- return commandsDocsProvider . TryImportRespCommandsData ( path ,
50
- streamProvider , out commandsData , logger ) ;
51
- }
52
- finally
53
- {
54
- // Unload the context
55
- assemblyLoadContext . Unload ( ) ;
28
+ var streamProvider =
29
+ StreamProviderFactory . GetStreamProvider ( FileLocationType . EmbeddedResource , null , resourcesAssembly ) ;
30
+ var commandsDocsProvider = RespCommandsDataProviderFactory . GetRespCommandsDataProvider < TData > ( ) ;
56
31
57
- // Force GC to release the loaded assembly
58
- GC . Collect ( ) ;
59
- GC . WaitForPendingFinalizers ( ) ;
60
- }
61
- }
32
+ return commandsDocsProvider . TryImportRespCommandsData ( path ,
33
+ streamProvider , out commandsData , logger ) ;
62
34
}
63
35
}
64
36
}
0 commit comments