aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Loading/src
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-09-11 16:43:36 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-09-11 16:43:36 -0400
commit0d47b4d25cf61d29c44a17ae491d775cf84938ab (patch)
treec308e670963c161febc1d8acba93ba6c9651ce91 /lib/VNLib.Plugins.Extensions.Loading/src
parent940f151f2f4e708282deb5569cffe5b0935f5c3b (diff)
Managed library & package updates
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading/src')
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs12
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs30
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs11
3 files changed, 27 insertions, 26 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs b/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs
index 49ef4b3..2d47af5 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/AssemblyLoader.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Loading
@@ -48,19 +48,19 @@ namespace VNLib.Plugins.Extensions.Loading
public sealed class AssemblyLoader<T> : ManagedLibrary, IDisposable
{
private readonly CancellationTokenRegistration _reg;
- private readonly Lazy<T> _instance;
+ private readonly LazyInitializer<T> _instance;
private bool disposedValue;
/// <summary>
/// The instance of the loaded type
/// </summary>
- public T Resource => _instance.Value;
+ public T Resource => _instance.Instance;
private AssemblyLoader(string assemblyPath, AssemblyLoadContext parentContext, CancellationToken unloadToken)
:base(assemblyPath, parentContext)
{
//Init lazy type loader
- _instance = new(LoadTypeFromAssembly<T>, LazyThreadSafetyMode.PublicationOnly);
+ _instance = new(LoadTypeFromAssembly<T>);
//Register dispose
_reg = unloadToken.Register(Dispose);
}
@@ -96,7 +96,7 @@ namespace VNLib.Plugins.Extensions.Loading
if (disposing)
{
//If the instance is disposable, call its dispose method on unload
- if (_instance.IsValueCreated && _instance.Value is IDisposable disposable)
+ if (_instance.IsLoaded && _instance.Instance is IDisposable disposable)
{
disposable.Dispose();
}
@@ -138,7 +138,7 @@ namespace VNLib.Plugins.Extensions.Loading
/// <exception cref="FileNotFoundException"></exception>
internal static AssemblyLoader<T> Load(string assemblyName, AssemblyLoadContext loadContext, CancellationToken unloadToken)
{
- _ = loadContext ?? throw new ArgumentNullException(nameof(loadContext));
+ ArgumentNullException.ThrowIfNull(loadContext);
//Make sure the file exists
if (!FileOperations.FileExists(assemblyName))
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
index d4ea8b0..30711fa 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/ConfigurationExtensions.cs
@@ -704,22 +704,22 @@ namespace VNLib.Plugins.Extensions.Loading
return [];
}
- if (searchPaths.ValueKind == JsonValueKind.Array)
+ switch (searchPaths.ValueKind)
{
- //Get the plugins path or throw because it should ALWAYS be defined if this method is called
- return searchPaths.EnumerateArray()
- .Select(static p => p.GetString()!)
- .Select(Path.GetFullPath) //Get absolute file paths
- .ToArray();
- }
- else if (searchPaths.ValueKind == JsonValueKind.String)
- {
- return [Path.GetFullPath(searchPaths.GetString()!)];
- }
- else
- {
- return [];
- }
+ case JsonValueKind.Array:
+
+ //Get the plugins path or throw because it should ALWAYS be defined if this method is called
+ return searchPaths.EnumerateArray()
+ .Select(static p => p.GetString()!)
+ .Select(Path.GetFullPath) //Get absolute file paths
+ .ToArray();
+
+ case JsonValueKind.String:
+ return [ Path.GetFullPath(searchPaths.GetString()!) ];
+
+ default:
+ return [];
+ }
}
}
}
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs b/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs
index 9fb66a2..a86129c 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/IAsyncBackgroundWork.cs
@@ -1,12 +1,12 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Loading
-* File: LoadingExtensions.cs
+* File: IAsyncBackgroundWork.cs
*
-* LoadingExtensions.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
+* IAsyncBackgroundWork.cs is part of VNLib.Plugins.Extensions.Loading which is
+* part of the larger VNLib collection of libraries and utilities.
*
* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -22,9 +22,10 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
+using System.Threading;
using System.Threading.Tasks;
+
using VNLib.Utils.Logging;
-using System.Threading;
namespace VNLib.Plugins.Extensions.Loading
{