Added plugin events
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using HopFrame.Core.Config;
|
||||
using System.Reflection;
|
||||
using HopFrame.Core.Config;
|
||||
using HopFrame.Web.Components.Layout;
|
||||
using HopFrame.Web.Models;
|
||||
using HopFrame.Web.Plugins;
|
||||
using HopFrame.Web.Plugins.Annotations;
|
||||
using HopFrame.Web.Plugins.Internal;
|
||||
|
||||
namespace HopFrame.Web;
|
||||
|
||||
@@ -28,5 +32,23 @@ public static class HopFrameConfiguratorExtensions {
|
||||
configuratorDelegate.Invoke(viewConfigurator);
|
||||
return configurator;
|
||||
}
|
||||
|
||||
public static HopFrameConfigurator AddPlugin<TPlugin>(this HopFrameConfigurator configurator) where TPlugin : HopFramePlugin {
|
||||
PluginOrchestrator.RegisterPlugin(configurator.ServiceCollection, typeof(TPlugin));
|
||||
|
||||
var methods = typeof(TPlugin).GetMethods()
|
||||
.Where(method => method.IsStatic)
|
||||
.Where(method => method.GetCustomAttributes(true)
|
||||
.Any(attr => attr is PluginConfiguratorAttribute))
|
||||
.Where(method => method.GetParameters().Length < 2);
|
||||
|
||||
foreach (var method in methods) {
|
||||
if (method.GetParameters().Length > 0)
|
||||
method.Invoke(null, [configurator]);
|
||||
else method.Invoke(null, []);
|
||||
}
|
||||
|
||||
return configurator;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user