aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-02 01:50:05 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-02 01:50:05 -0400
commit9768aa7713826d49a6c2ea1025caa4b87d62e5e8 (patch)
tree327525a94b1fbe8b11591eeb1b3d2941a6e58c06 /lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs
parentc5b9f9b64933a288362fc08bea8a461e5e260b16 (diff)
also carried away
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs87
1 files changed, 47 insertions, 40 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs b/lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs
index 7731bcf..1061dda 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/RoutingExtensions.cs
@@ -54,58 +54,65 @@ namespace VNLib.Plugins.Extensions.Loading.Routing
Type endpointType = typeof(T);
T endpoint;
-
- //If the config attribute is not set, then ignore the config variables
- if (string.IsNullOrWhiteSpace(pluginConfigPathName))
- {
- ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase) });
-
- _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p) found for {endpointType.Name}");
-
- //Create the new endpoint and pass the plugin instance
- endpoint = (T)constructor.Invoke(new object[] { plugin });
-
- //Register event handlers for the endpoint
- ScheduleIntervals(plugin, endpoint, endpointType, null);
- }
- else
+ try
{
- //Try to get config but allow null if not required
- IConfigScope? config = plugin.TryGetConfig(pluginConfigPathName);
-
- if(configRequired && config == null)
- {
- ConfigurationExtensions.ThrowConfigNotFoundForType(endpointType);
- return default;
- }
-
- //Choose constructor based on config
- if (config != null)
+ //If the config attribute is not set, then ignore the config variables
+ if (string.IsNullOrWhiteSpace(pluginConfigPathName))
{
- ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase), typeof(IConfigScope) });
+ ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase) });
- //Make sure the constructor exists
- _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p, IConfigScope cs) found for {endpointType.Name}");
+ _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p) found for {endpointType.Name}");
- //Create the new endpoint and pass the plugin instance along with the configuration object
- endpoint = (T)constructor.Invoke(new object[] { plugin, config });
+ //Create the new endpoint and pass the plugin instance
+ endpoint = (T)constructor.Invoke(new object[] { plugin });
//Register event handlers for the endpoint
- ScheduleIntervals(plugin, endpoint, endpointType, config);
+ ScheduleIntervals(plugin, endpoint, endpointType, null);
}
else
{
- //Config does not exist, so use the default constructor
- ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase) });
+ //Try to get config but allow null if not required
+ IConfigScope? config = plugin.TryGetConfig(pluginConfigPathName);
- _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p) found for {endpointType.Name}");
+ if (configRequired && config == null)
+ {
+ ConfigurationExtensions.ThrowConfigNotFoundForType(endpointType);
+ return default;
+ }
- //Create the new endpoint and pass the plugin instance
- endpoint = (T)constructor.Invoke(new object[] { plugin });
+ //Choose constructor based on config
+ if (config != null)
+ {
+ ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase), typeof(IConfigScope) });
- //Register event handlers for the endpoint
- ScheduleIntervals(plugin, endpoint, endpointType, null);
- }
+ //Make sure the constructor exists
+ _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p, IConfigScope cs) found for {endpointType.Name}");
+
+ //Create the new endpoint and pass the plugin instance along with the configuration object
+ endpoint = (T)constructor.Invoke(new object[] { plugin, config });
+
+ //Register event handlers for the endpoint
+ ScheduleIntervals(plugin, endpoint, endpointType, config);
+ }
+ else
+ {
+ //Config does not exist, so use the default constructor
+ ConstructorInfo? constructor = endpointType.GetConstructor(new Type[] { typeof(PluginBase) });
+
+ _ = constructor ?? throw new EntryPointNotFoundException($"No constructor t(PluginBase p) found for {endpointType.Name}");
+
+ //Create the new endpoint and pass the plugin instance
+ endpoint = (T)constructor.Invoke(new object[] { plugin });
+
+ //Register event handlers for the endpoint
+ ScheduleIntervals(plugin, endpoint, endpointType, null);
+ }
+ }
+ }
+ catch(TargetInvocationException te)
+ {
+ LoadingExtensions.FindAndThrowInnerException(te);
+ throw;
}
//Route the endpoint