Added plugin events

This commit is contained in:
2025-02-02 19:06:41 +01:00
parent 4cfeaab652
commit 13e9af892c
28 changed files with 415 additions and 87 deletions

View File

@@ -1,5 +1,6 @@
using HopFrame.Core.Events;
using HopFrame.Core.Callbacks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace HopFrame.Core.Config;
@@ -8,18 +9,20 @@ public class HopFrameConfig {
public bool DisplayUserInfo { get; set; } = true;
public string? BasePolicy { get; set; }
public string? LoginPageRewrite { get; set; }
public List<HopEventHandler> Handlers { get; } = new();
public List<HopCallbackHandler> Handlers { get; } = new();
}
/// <summary>
/// A helper class for editing the <see cref="HopFrameConfig"/>
/// </summary>
public class HopFrameConfigurator(HopFrameConfig config) {
public class HopFrameConfigurator(HopFrameConfig config, IServiceCollection collection = null!) {
/// <summary>
/// The Internal HopFrame configuration that's modified by the helper functions
/// </summary>
public HopFrameConfig InnerConfig { get; } = config;
public IServiceCollection ServiceCollection { get; } = collection;
/// <summary>
/// Adds all tables defined in the DbContext to the HopFrame ui and configures it using the provided configurator
@@ -45,6 +48,18 @@ public class HopFrameConfigurator(HopFrameConfig config) {
return new DbContextConfigurator<TDbContext>(context);
}
public bool HasDbContext<TDbContext>() where TDbContext : DbContext {
return InnerConfig.Contexts.Any(context => context.ContextType == typeof(TDbContext));
}
public DbContextConfigurator<TDbContext>? GetDbContext<TDbContext>() where TDbContext : DbContext {
var config = InnerConfig.Contexts
.SingleOrDefault(context => context.ContextType == typeof(TDbContext));
if (config is null) return null;
return new DbContextConfigurator<TDbContext>(config);
}
/// <summary>
/// Determines if the name of the currently logged-in user should be displayed in the top right corner of the admin ui
/// </summary>