diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml
index 9070783..29bf02a 100644
--- a/.idea/.idea.HopFrame/.idea/workspace.xml
+++ b/.idea/.idea.HopFrame/.idea/workspace.xml
@@ -12,8 +12,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -105,14 +125,14 @@
"keyToString": {
".NET Launch Settings Profile.HopFrame.Testing.Api: https.executor": "Run",
".NET Launch Settings Profile.HopFrame.Testing.executor": "Run",
- ".NET Launch Settings Profile.HopFrame.Testing: https.executor": "Run",
+ ".NET Launch Settings Profile.HopFrame.Testing: https.executor": "Debug",
".NET Project.HopFrame.Testing.executor": "Run",
"72b118b0-a6fc-4561-acdf-74f0b454dbb8.executor": "Debug",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"b5f11219-dfc4-47a1-b02c-90ab603034fb.executor": "Debug",
"dcdf1689-dc07-47e4-8824-2e60a4fbf301.executor": "Debug",
- "git-widget-placeholder": "!27 on fix/selection",
+ "git-widget-placeholder": "!28 on feature/events",
"list.type.of.created.stylesheet": "CSS",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
@@ -220,7 +240,8 @@
-
+
+
@@ -470,7 +491,23 @@
1738084259089
-
+
+
+ 1738337068205
+
+
+
+ 1738337068205
+
+
+
+ 1738337314351
+
+
+
+ 1738337314351
+
+
@@ -521,8 +558,6 @@
-
-
@@ -546,6 +581,27 @@
-
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/EventEmitter.cs
+ 19
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/HopFrame.Core/Config/DbContextConfig.cs b/src/HopFrame.Core/Config/DbContextConfig.cs
index 9daed12..005e0bf 100644
--- a/src/HopFrame.Core/Config/DbContextConfig.cs
+++ b/src/HopFrame.Core/Config/DbContextConfig.cs
@@ -1,13 +1,16 @@
-using Microsoft.EntityFrameworkCore;
+using HopFrame.Core.Events;
+using Microsoft.EntityFrameworkCore;
namespace HopFrame.Core.Config;
public class DbContextConfig {
public Type ContextType { get; }
public List Tables { get; } = new();
+ public HopFrameConfig ParentConfig { get; }
- public DbContextConfig(Type context) {
+ public DbContextConfig(Type context, HopFrameConfig parentConfig) {
ContextType = context;
+ ParentConfig = parentConfig;
foreach (var property in ContextType.GetProperties()) {
if (!property.PropertyType.IsGenericType) continue;
diff --git a/src/HopFrame.Core/Config/HopFrameConfig.cs b/src/HopFrame.Core/Config/HopFrameConfig.cs
index 732d367..d5593bd 100644
--- a/src/HopFrame.Core/Config/HopFrameConfig.cs
+++ b/src/HopFrame.Core/Config/HopFrameConfig.cs
@@ -1,4 +1,5 @@
-using Microsoft.EntityFrameworkCore;
+using HopFrame.Core.Events;
+using Microsoft.EntityFrameworkCore;
namespace HopFrame.Core.Config;
@@ -7,6 +8,7 @@ public class HopFrameConfig {
public bool DisplayUserInfo { get; set; } = true;
public string? BasePolicy { get; set; }
public string? LoginPageRewrite { get; set; }
+ public List Handlers { get; } = new();
}
///
@@ -38,7 +40,7 @@ public class HopFrameConfigurator(HopFrameConfig config) {
/// The configurator used for the DbContext
///
public DbContextConfigurator AddDbContext() where TDbContext : DbContext {
- var context = new DbContextConfig(typeof(TDbContext));
+ var context = new DbContextConfig(typeof(TDbContext), InnerConfig);
InnerConfig.Contexts.Add(context);
return new DbContextConfigurator(context);
}
diff --git a/src/HopFrame.Core/Config/TableConfig.cs b/src/HopFrame.Core/Config/TableConfig.cs
index 97b40ce..fe5d9e3 100644
--- a/src/HopFrame.Core/Config/TableConfig.cs
+++ b/src/HopFrame.Core/Config/TableConfig.cs
@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq.Expressions;
using System.Reflection;
+using HopFrame.Core.Events;
namespace HopFrame.Core.Config;
@@ -188,6 +189,36 @@ public class TableConfigurator(TableConfig config) {
InnerConfig.DeletePolicy = policy;
return this;
}
+
+ ///
+ /// Adds an event handler of the provided type
+ ///
+ /// The type of event that triggers the handler
+ /// The handler delegate
+ public TableConfigurator AddEventHandler(EventType type, Func handler) {
+ var eventName = EventTypes.ConstructEventName(type, InnerConfig);
+ var handlerStore = new HopEventHandler(eventName, (o, provider) => handler.Invoke((TModel)o, provider));
+ InnerConfig.ContextConfig.ParentConfig.Handlers.Add(handlerStore);
+
+ return this;
+ }
+
+ ///
+ /// Adds an event handler of the provided type
+ ///
+ /// The type of event that triggers the handler
+ /// The handler delegate
+ public TableConfigurator AddEventHandler(EventType type, Action handler) {
+ var eventName = EventTypes.ConstructEventName(type, InnerConfig);
+ var handlerStore = new HopEventHandler(eventName, (o, provider) => {
+ handler.Invoke((TModel)o, provider);
+ return Task.CompletedTask;
+ });
+
+ InnerConfig.ContextConfig.ParentConfig.Handlers.Add(handlerStore);
+
+ return this;
+ }
internal static PropertyInfo GetPropertyInfo(Expression> propertyLambda) {
if (propertyLambda.Body is not MemberExpression member) {
diff --git a/src/HopFrame.Core/Events/EventTypes.cs b/src/HopFrame.Core/Events/EventTypes.cs
new file mode 100644
index 0000000..d2ad751
--- /dev/null
+++ b/src/HopFrame.Core/Events/EventTypes.cs
@@ -0,0 +1,31 @@
+using HopFrame.Core.Config;
+
+namespace HopFrame.Core.Events;
+
+public static class EventTypes {
+
+ private const string Prefix = "HopFrame.";
+ private const string CreateEntryPrefix = Prefix + "Entry.Create.";
+ private const string UpdateEntryPrefix = Prefix + "Entry.Update.";
+ private const string DeleteEntryPrefix = Prefix + "Entry.Delete.";
+
+ public static string CreateEntry(TableConfig config) => CreateEntryPrefix + config.PropertyName;
+ public static string UpdateEntry(TableConfig config) => UpdateEntryPrefix + config.PropertyName;
+ public static string DeleteEntry(TableConfig config) => DeleteEntryPrefix + config.PropertyName;
+
+ public static string ConstructEventName(EventType type, TableConfig config) {
+ return type switch {
+ EventType.CreateEntry => CreateEntry(config),
+ EventType.UpdateEntry => UpdateEntry(config),
+ EventType.DeleteEntry => DeleteEntry(config),
+ _ => Prefix
+ };
+ }
+
+}
+
+public enum EventType {
+ CreateEntry = 0,
+ UpdateEntry = 1,
+ DeleteEntry = 2
+}
diff --git a/src/HopFrame.Core/Events/HopEventHandler.cs b/src/HopFrame.Core/Events/HopEventHandler.cs
new file mode 100644
index 0000000..b3767b4
--- /dev/null
+++ b/src/HopFrame.Core/Events/HopEventHandler.cs
@@ -0,0 +1,7 @@
+namespace HopFrame.Core.Events;
+
+public readonly struct HopEventHandler(string eventType, Func