From 0d47b4d25cf61d29c44a17ae491d775cf84938ab Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 11 Sep 2024 16:43:36 -0400 Subject: Managed library & package updates --- .../src/AssemblyLoader.cs | 12 ++++----- .../src/ConfigurationExtensions.cs | 30 +++++++++++----------- .../src/IAsyncBackgroundWork.cs | 11 ++++---- 3 files changed, 27 insertions(+), 26 deletions(-) (limited to 'lib/VNLib.Plugins.Extensions.Loading/src') 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 : ManagedLibrary, IDisposable { private readonly CancellationTokenRegistration _reg; - private readonly Lazy _instance; + private readonly LazyInitializer _instance; private bool disposedValue; /// /// The instance of the loaded type /// - 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, LazyThreadSafetyMode.PublicationOnly); + _instance = new(LoadTypeFromAssembly); //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 /// internal static AssemblyLoader 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 { -- cgit