From 4ef0142747c4a0dd0c4cb71d8e7359c03b3a2942 Mon Sep 17 00:00:00 2001 From: vnugent Date: Tue, 2 Jan 2024 02:33:05 -0500 Subject: breaking changes: plugin service pools & move plugin api away from web related --- .../src/Construction/SsBuilderExtensions.cs | 6 ++--- .../src/IManagedPlugin.cs | 8 +------ .../src/IManualPlugin.cs | 8 +------ .../src/PluginExtensions.cs | 22 ++++++++++-------- .../src/PluginLoadEventListener.cs | 2 +- .../src/PluginManager.cs | 2 +- .../src/PluginStackInitializer.cs | 27 ++++------------------ .../src/ServiceGroup.cs | 6 +++-- 8 files changed, 27 insertions(+), 54 deletions(-) (limited to 'lib/Plugins.Essentials.ServiceStack') diff --git a/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs b/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs index ee49f99..d96809b 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack @@ -185,9 +185,7 @@ namespace VNLib.Plugins.Essentials.ServiceStack.Construction private static void OnPluginServiceEvent(this IManagedPlugin plugin, Action loader) { - object? service = plugin.Services.GetService(typeof(T)); - - if (service is T s) + if (plugin.Services.GetService(typeof(T)) is T s) { loader(s); } diff --git a/lib/Plugins.Essentials.ServiceStack/src/IManagedPlugin.cs b/lib/Plugins.Essentials.ServiceStack/src/IManagedPlugin.cs index 21c8e91..8332f7e 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/IManagedPlugin.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/IManagedPlugin.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack @@ -41,12 +41,6 @@ namespace VNLib.Plugins.Essentials.ServiceStack /// IServiceContainer Services { get; } - /// - /// Internal call to get all exported plugin endpoints - /// - /// - internal IEndpoint[] GetEndpoints(); - /// /// Internal notification that the plugin is loaded /// diff --git a/lib/Plugins.Essentials.ServiceStack/src/IManualPlugin.cs b/lib/Plugins.Essentials.ServiceStack/src/IManualPlugin.cs index e58067f..cecd481 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/IManualPlugin.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/IManualPlugin.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack @@ -44,12 +44,6 @@ namespace VNLib.Plugins.Essentials.ServiceStack /// The container to add services to void GetAllExportedServices(IServiceContainer container); - /// - /// Collects all exported endpoints to put into service - /// - /// The collection of endpoints - IEndpoint[] GetEndpoints(); - /// /// Initializes the plugin, called before accessing any other methods /// diff --git a/lib/Plugins.Essentials.ServiceStack/src/PluginExtensions.cs b/lib/Plugins.Essentials.ServiceStack/src/PluginExtensions.cs index d93df6d..d8cdf75 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/PluginExtensions.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/PluginExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack @@ -26,7 +26,7 @@ using System.Linq; using System.Collections.Generic; using VNLib.Utils.Logging; -using VNLib.Plugins.Runtime; +using VNLib.Plugins.Essentials.Runtime; namespace VNLib.Plugins.Essentials.ServiceStack { @@ -40,14 +40,18 @@ namespace VNLib.Plugins.Essentials.ServiceStack /// /// /// The enumeration of web endpoints - internal static IEnumerable GetEndpoints(this IPlugin plugin) => ((IWebPlugin)plugin).GetEndpoints(); + internal static IEnumerable GetEndpoints(this IManagedPlugin plugin) + { + //Try to get the endpoint defintion + if (plugin.Services.GetService(typeof(IVirtualEndpointDefinition)) is IVirtualEndpointDefinition defintion) + { + //Return the endpoints from the definition + return defintion.GetEndpoints(); + } - /// - /// Gets only plugins that implement interface - /// - /// - /// - internal static IEnumerable GetOnlyWebPlugins(this PluginController controller) => controller.Plugins.Where(static p => p.Plugin is IWebPlugin); + //If the plugin does not have an endpoint definition, return an empty enumeration + return Enumerable.Empty(); + } /// /// Loads all plugins that implement interface into the diff --git a/lib/Plugins.Essentials.ServiceStack/src/PluginLoadEventListener.cs b/lib/Plugins.Essentials.ServiceStack/src/PluginLoadEventListener.cs index 0eaa3a8..b24019b 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/PluginLoadEventListener.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/PluginLoadEventListener.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack diff --git a/lib/Plugins.Essentials.ServiceStack/src/PluginManager.cs b/lib/Plugins.Essentials.ServiceStack/src/PluginManager.cs index ba3b91a..f5f2abc 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/PluginManager.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/PluginManager.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack diff --git a/lib/Plugins.Essentials.ServiceStack/src/PluginStackInitializer.cs b/lib/Plugins.Essentials.ServiceStack/src/PluginStackInitializer.cs index c2ff1e4..e6489c9 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/PluginStackInitializer.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/PluginStackInitializer.cs @@ -26,7 +26,6 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using System.Diagnostics; using System.Threading.Tasks; using System.Collections.Generic; @@ -35,7 +34,7 @@ using System.ComponentModel.Design; using VNLib.Utils.Logging; using VNLib.Plugins.Runtime; using VNLib.Utils.Extensions; -using VNLib.Plugins.Attributes; +using VNLib.Plugins.Runtime.Services; namespace VNLib.Plugins.Essentials.ServiceStack { @@ -229,9 +228,6 @@ namespace VNLib.Plugins.Essentials.ServiceStack } } - /// - IEndpoint[] IManagedPlugin.GetEndpoints() => Plugin.Controller.GetOnlyWebPlugins().SelectMany(static pl => pl.Plugin!.GetEndpoints()).ToArray(); - /* * Automatically called after the plugin has successfully loaded * by event handlers below @@ -246,21 +242,9 @@ namespace VNLib.Plugins.Essentials.ServiceStack //Init new service container _services = new(); - //Get types from plugin - foreach (LivePlugin plugin in Plugin.Controller.Plugins) - { - /* - * Get the exposed configurator method if declared, - * it may not be defined. - */ - ServiceConfigurator? callback = plugin.PluginType.GetMethods() - .Where(static m => m.GetCustomAttribute() != null && !m.IsAbstract) - .Select(m => m.CreateDelegate(plugin.Plugin)) - .FirstOrDefault(); - - //Invoke if defined to expose services - callback?.Invoke(_services); - } + //Get all exported services and add them to the container + PluginServiceExport[] exports = Plugin.Controller.GetExportedServices(); + Array.ForEach(exports, e => _services.AddService(e.ServiceType, e.Service, true)); } /// @@ -298,9 +282,6 @@ namespace VNLib.Plugins.Essentials.ServiceStack /// public IServiceContainer Services => _container; - /// - IEndpoint[] IManagedPlugin.GetEndpoints() => Plugin.GetEndpoints(); - public void Load() { Plugin.Load(); diff --git a/lib/Plugins.Essentials.ServiceStack/src/ServiceGroup.cs b/lib/Plugins.Essentials.ServiceStack/src/ServiceGroup.cs index e504013..da34d54 100644 --- a/lib/Plugins.Essentials.ServiceStack/src/ServiceGroup.cs +++ b/lib/Plugins.Essentials.ServiceStack/src/ServiceGroup.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.ServiceStack @@ -23,6 +23,7 @@ */ using System.Net; +using System.Linq; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -82,7 +83,8 @@ namespace VNLib.Plugins.Essentials.ServiceStack internal void OnPluginLoaded(IManagedPlugin plugin) { //Get all new endpoints for plugin - IEndpoint[] newEndpoints = plugin.GetEndpoints(); + IEndpoint[] newEndpoints = plugin.GetEndpoints() + .ToArray(); //Add endpoints to dict _endpointsForPlugins.AddOrUpdate(plugin, newEndpoints); -- cgit