aboutsummaryrefslogtreecommitdiff
path: root/VNLib.Plugins.Extensions.Loading.Users
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-11-18 16:01:38 -0500
committerLibravatar vman <public@vaughnnugent.com>2022-11-18 16:01:38 -0500
commitae7d863808c6c00999d20408beeda3731509c40c (patch)
tree939de3a994e614af88c4fba522dadb251d6b85db /VNLib.Plugins.Extensions.Loading.Users
parent3fb601d14354c867e1ead94b027c99c4a2fc15b5 (diff)
Namespace changes and dynamic user lib loading
Diffstat (limited to 'VNLib.Plugins.Extensions.Loading.Users')
-rw-r--r--VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs83
-rw-r--r--VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj24
2 files changed, 0 insertions, 107 deletions
diff --git a/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs b/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs
deleted file mode 100644
index 40e0b03..0000000
--- a/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using System.Text.Json;
-using System.Runtime.CompilerServices;
-
-using VNLib.Utils.Logging;
-using VNLib.Utils.Extensions;
-
-using VNLib.Plugins.Essentials.Users;
-using VNLib.Plugins.Extensions.Loading.Sql;
-
-namespace VNLib.Plugins.Extensions.Loading.Users
-{
- /// <summary>
- /// Contains extension methods for plugins to load the "users" system
- /// </summary>
- public static class UserLoading
- {
- public const string USER_TABLE_KEY = "user_table";
- public const string USER_CUSTOM_ASSEMBLY = "user_custom_asm";
-
- private static readonly ConditionalWeakTable<PluginBase, Lazy<IUserManager>> UsersTable = new();
-
- /// <summary>
- /// Gets or loads the plugin's ambient <see cref="IUserManager"/>, with the specified user-table name,
- /// or the default table name
- /// </summary>
- /// <param name="plugin"></param>
- /// <returns>The ambient <see cref="IUserManager"/> for the current plugin</returns>
- /// <exception cref="KeyNotFoundException"></exception>
- /// <exception cref="ObjectDisposedException"></exception>
- public static IUserManager GetUserManager(this PluginBase plugin)
- {
- plugin.ThrowIfUnloaded();
- //Get stored or load
- return UsersTable.GetValue(plugin, LoadUsers).Value;
- }
-
- private static Lazy<IUserManager> LoadUsers(PluginBase pbase)
- {
- //lazy callack
- IUserManager LoadManager()
- {
- IUserManager man;
-
- //Try to load a custom user assembly for exporting IUserManager
- string? customAsm = pbase.PluginConfig.GetPropString(USER_CUSTOM_ASSEMBLY);
- //See if host config defined the path
- customAsm ??= pbase.HostConfig.GetPropString(USER_CUSTOM_ASSEMBLY);
-
- if (!string.IsNullOrWhiteSpace(customAsm))
- {
- //Try to load a custom assembly
- AssemblyLoader<IUserManager> loader = pbase.LoadAssembly<IUserManager>(customAsm);
- try
- {
- //Return the loaded instance (may raise exception)
- man = loader.Resource;
- }
- catch
- {
- loader.Dispose();
- throw;
- }
- pbase.Log.Verbose("Loaded custom user managment assembly");
- }
- else
- {
- //Default table name to
- string? userTableName = "Users";
- //Try to get the user-table element from plugin config
- if (pbase.PluginConfig.TryGetProperty(USER_TABLE_KEY, out JsonElement userEl))
- {
- userTableName = userEl.GetString();
- }
- _ = userTableName ?? throw new KeyNotFoundException($"Missing required key '{USER_TABLE_KEY}' in config");
- //Load user-manager
- man = new UserManager(pbase.GetConnectionFactory(), userTableName);
- }
- return man;
- }
- return new Lazy<IUserManager>(LoadManager, LazyThreadSafetyMode.PublicationOnly);
- }
- }
-} \ No newline at end of file
diff --git a/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj b/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj
deleted file mode 100644
index f3e58c6..0000000
--- a/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj
+++ /dev/null
@@ -1,24 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- <PlatformTarget>x64</PlatformTarget>
- <Version>1.0.0.1</Version>
- <Authors>Vaughn Nugent</Authors>
- <Copyright>Copyright © 2022 Vaughn Nugent</Copyright>
- <PackageProjectUrl>https://www.vaughnnugent.com/resources</PackageProjectUrl>
- <GenerateDocumentationFile>True</GenerateDocumentationFile>
- <Platforms>AnyCPU;x64</Platforms>
- </PropertyGroup>
-
- <ItemGroup>
- <ProjectReference Include="..\..\..\VNLib\Essentials\VNLib.Plugins.Essentials.csproj" />
- <ProjectReference Include="..\..\Essentials\VNLib.Plugins.Essentials.Users\VNLib.Plugins.Essentials.Users.csproj" />
- <ProjectReference Include="..\..\PluginBase\VNLib.Plugins.PluginBase.csproj" />
- <ProjectReference Include="..\VNLib.Plugins.Extensions.Loading.Sql\VNLib.Plugins.Extensions.Loading.Sql.csproj" />
- <ProjectReference Include="..\VNLib.Plugins.Extensions.Loading\VNLib.Plugins.Extensions.Loading.csproj" />
- </ItemGroup>
-
-</Project>