From 1350c983c371fdd6a93596c8474345f9168284e1 Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 22 May 2024 15:28:54 -0400 Subject: Squashed commit of the following: commit 27fb5382d80d9bcfb4c65974bbae20c5e7b8ccbc Author: vnugent Date: Wed May 22 00:57:34 2024 -0400 feat: Vault environment vars commit 69f13e43dfdd8069459800ccc3039f45fc884814 Author: vnugent Date: Wed May 15 22:04:43 2024 -0400 fix: #3 Defer vault loading until a secret actually needs it commit c848787d4830a73e9ba93898897282be2f3752f2 Author: vnugent Date: Wed May 15 22:02:02 2024 -0400 package updates commit 21c6c85f540740ac29536a7091346a731aa85148 Author: vnugent Date: Wed May 15 22:01:16 2024 -0400 fix: #3 Error raised when managed password type disposed commit 8e77289041349b16536497f48f0c0a4ec6fe30f5 Author: vnugent Date: Thu May 2 15:44:42 2024 -0400 feat: #2 Middleware helpers, proj cleanup, fix sync secrets, vault client commit e0a5c85297516188e57b54d9b530b2482cb03eb0 Merge: a977dab 5ad520e Author: vnugent Date: Sat Apr 27 17:44:09 2024 -0400 Merge branch 'master' into develop commit a977dabef1dec915e00f755cb3ee3363aa9985f1 Author: vnugent Date: Sat Apr 27 17:26:35 2024 -0400 chore: package updates commit a2e2c3c4152d000b8df25c3c3fee14d491aab2c6 Merge: f03b727 87bfa83 Author: vnugent Date: Sat Apr 20 12:11:45 2024 -0400 Merge branch 'master' into develop commit f03b727d8f8e52f1dbd6293ea5c5a492c6d8e2da Author: vnugent Date: Sat Apr 20 12:02:07 2024 -0400 chore: Package updates --- .../src/Routing/MiddlewareHelpers.cs | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/VNLib.Plugins.Extensions.Loading/src/Routing/MiddlewareHelpers.cs (limited to 'lib/VNLib.Plugins.Extensions.Loading/src/Routing/MiddlewareHelpers.cs') diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/Routing/MiddlewareHelpers.cs b/lib/VNLib.Plugins.Extensions.Loading/src/Routing/MiddlewareHelpers.cs new file mode 100644 index 0000000..6a0d848 --- /dev/null +++ b/lib/VNLib.Plugins.Extensions.Loading/src/Routing/MiddlewareHelpers.cs @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Library: VNLib +* Package: VNLib.Plugins.Extensions.Loading +* File: MiddlewareHelpers.cs +* +* MiddlewareHelpers.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 +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* VNLib.Plugins.Extensions.Loading is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see https://www.gnu.org/licenses/. +*/ + +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +using VNLib.Utils.Extensions; +using VNLib.Plugins.Essentials.Middleware; + +namespace VNLib.Plugins.Extensions.Loading.Routing +{ + /// + /// Provides helper extensions for http middleware + /// + public static class MiddlewareHelpers + { + private static readonly ConditionalWeakTable> _pluginMiddlewareList = new(); + + /// + /// Exports a single middlware instance to the collection for the plugin. + /// + /// + /// + /// A params array of middleware instances to export to the plugin + /// + /// WARNING: Adding middleware arrays explicitly to the plugin service pool will override + /// this function. All instances must be exposed though this function + /// + public static void ExportMiddleware(this PluginBase plugin, params T[] instances) where T : IHttpMiddleware + { + /* + * The runtime accepts an enumeration of IHttpMiddleware instances, so + * a list can just be exported as an enumerable instance + */ + static List OnCreate(PluginBase plugin) + { + List collection = new(1); + plugin.ExportService>(collection); + return collection; + } + + //Get the endpoint collection for the current plugin + List middlewares = _pluginMiddlewareList.GetValue(plugin, OnCreate); + + //Add the endpoint to the collection + instances.ForEach(mw => middlewares.Add(mw)); + } + } +} -- cgit