diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml
index fe26cba..cb2bebd 100644
--- a/.idea/.idea.HopFrame/.idea/workspace.xml
+++ b/.idea/.idea.HopFrame/.idea/workspace.xml
@@ -11,9 +11,25 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -33,7 +49,7 @@
@@ -62,6 +78,7 @@
+
@@ -79,6 +96,7 @@
+
@@ -118,28 +136,28 @@
- {
- "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 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": "dev",
- "list.type.of.created.stylesheet": "CSS",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -258,7 +276,8 @@
-
+
+
@@ -644,7 +663,15 @@
1740742749325
-
+
+
+ 1740743139064
+
+
+
+ 1740743139064
+
+
@@ -695,7 +722,6 @@
-
@@ -720,6 +746,7 @@
-
+
+
\ No newline at end of file
diff --git a/src/HopFrame.Core/Config/DbContextConfig.cs b/src/HopFrame.Core/Config/DbContextConfig.cs
index 8dba413..a8dd407 100644
--- a/src/HopFrame.Core/Config/DbContextConfig.cs
+++ b/src/HopFrame.Core/Config/DbContextConfig.cs
@@ -2,7 +2,13 @@
namespace HopFrame.Core.Config;
-public class DbContextConfig {
+public interface ITableGroupConfig {
+ public Type ContextType { get; }
+ public List Tables { get; }
+ public HopFrameConfig ParentConfig { get; }
+}
+
+public class DbContextConfig : ITableGroupConfig {
public Type ContextType { get; }
public List Tables { get; } = new();
public HopFrameConfig ParentConfig { get; }
diff --git a/src/HopFrame.Core/Config/HopFrameConfig.cs b/src/HopFrame.Core/Config/HopFrameConfig.cs
index e04fd07..57aabde 100644
--- a/src/HopFrame.Core/Config/HopFrameConfig.cs
+++ b/src/HopFrame.Core/Config/HopFrameConfig.cs
@@ -1,11 +1,13 @@
-using HopFrame.Core.Callbacks;
+using System.Linq.Expressions;
+using HopFrame.Core.Callbacks;
+using HopFrame.Core.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace HopFrame.Core.Config;
public class HopFrameConfig {
- public List Contexts { get; } = new();
+ public List Contexts { get; } = new();
public bool DisplayUserInfo { get; set; } = true;
public string? BasePolicy { get; set; }
public string? LoginPageRewrite { get; set; }
@@ -48,6 +50,36 @@ public sealed class HopFrameConfigurator(HopFrameConfig config, IServiceCollecti
return new DbContextConfigurator(context);
}
+ ///
+ /// Adds a table of the desired type and configures it to use a custom repository
+ ///
+ /// The key of the model
+ /// The configurator used for configuring the table page
+ /// The repository class that inherits from the (needs to be registered as a service)
+ /// The model of the table
+ /// The type of the primary key
+ public HopFrameConfigurator AddCustomRepository(Expression> keyExpression, Action> configurator) {
+ var context = AddCustomRepository(keyExpression);
+ configurator.Invoke(context);
+ return this;
+ }
+
+ ///
+ /// Adds a table of the desired type and configures it to use a custom repository
+ ///
+ /// The key of the model
+ /// The repository class that inherits from the (needs to be registered as a service)
+ /// The model of the table
+ /// The type of the primary key
+ /// The configurator used for configuring the table page
+ public TableConfigurator AddCustomRepository(Expression> keyExpression) {
+ var keyProperty = TableConfigurator.GetPropertyInfo(keyExpression);
+ var context = new RepositoryGroupConfig(typeof(TRepository), keyProperty, InnerConfig);
+ context.Tables.Add(new TableConfig(context, typeof(TModel), typeof(TRepository).Name, 0));
+ InnerConfig.Contexts.Add(context);
+ return new TableConfigurator(context.Tables[0]);
+ }
+
///
/// Check if a context is already registered in the HopFrame
///
@@ -64,6 +96,7 @@ public sealed class HopFrameConfigurator(HopFrameConfig config, IServiceCollecti
/// The configurator of the context if it already was defined, null if not
public DbContextConfigurator? GetDbContext() where TDbContext : DbContext {
var config = InnerConfig.Contexts
+ .OfType()
.SingleOrDefault(context => context.ContextType == typeof(TDbContext));
if (config is null) return null;
diff --git a/src/HopFrame.Core/Config/RepositoryGroupConfig.cs b/src/HopFrame.Core/Config/RepositoryGroupConfig.cs
new file mode 100644
index 0000000..40b10dc
--- /dev/null
+++ b/src/HopFrame.Core/Config/RepositoryGroupConfig.cs
@@ -0,0 +1,13 @@
+using System.Reflection;
+
+namespace HopFrame.Core.Config;
+
+public class RepositoryGroupConfig(Type repoType, PropertyInfo keyProperty, HopFrameConfig config) : ITableGroupConfig {
+ public Type ContextType { get; } = repoType;
+
+ public List Tables { get; } = new();
+
+ public HopFrameConfig ParentConfig { get; } = config;
+
+ public PropertyInfo KeyProperty { get; } = keyProperty;
+}
\ No newline at end of file
diff --git a/src/HopFrame.Core/Config/TableConfig.cs b/src/HopFrame.Core/Config/TableConfig.cs
index 455ca48..2de5648 100644
--- a/src/HopFrame.Core/Config/TableConfig.cs
+++ b/src/HopFrame.Core/Config/TableConfig.cs
@@ -11,7 +11,7 @@ public class TableConfig {
public string PropertyName { get; }
public string DisplayName { get; set; }
public string? Description { get; set; }
- public DbContextConfig ContextConfig { get; }
+ public ITableGroupConfig ContextConfig { get; }
public bool Ignored { get; set; }
public int Order { get; set; }
internal bool Seeded { get; set; }
@@ -23,7 +23,7 @@ public class TableConfig {
public List Properties { get; } = new();
- public TableConfig(DbContextConfig config, Type tableType, string propertyName, int nthTable) {
+ public TableConfig(ITableGroupConfig config, Type tableType, string propertyName, int nthTable) {
TableType = tableType;
PropertyName = propertyName;
ContextConfig = config;
diff --git a/src/HopFrame.Core/Repositories/IHopFrameRepository.cs b/src/HopFrame.Core/Repositories/IHopFrameRepository.cs
new file mode 100644
index 0000000..c4f09e2
--- /dev/null
+++ b/src/HopFrame.Core/Repositories/IHopFrameRepository.cs
@@ -0,0 +1,24 @@
+namespace HopFrame.Core.Repositories;
+
+public interface IHopFrameRepository where TModel : class {
+
+ Task> LoadPage(int page, int perPage);
+
+ Task> Search(string searchTerm, int page, int perPage);
+
+ Task GetTotalPageCount(int perPage);
+
+ Task CreateItem(TModel item);
+
+ Task EditItem(TModel item);
+
+ Task DeleteItem(TModel item);
+
+ Task GetOne(TKey key);
+
+}
+
+public readonly struct SearchResult(IEnumerable items, int pageCount) {
+ public IEnumerable Items { get; init; } = items;
+ public int PageCount { get; init; } = pageCount;
+}
diff --git a/src/HopFrame.Core/Services/ITableManager.cs b/src/HopFrame.Core/Services/ITableManager.cs
index 2078d10..0f8fac7 100644
--- a/src/HopFrame.Core/Services/ITableManager.cs
+++ b/src/HopFrame.Core/Services/ITableManager.cs
@@ -4,7 +4,7 @@ using HopFrame.Core.Config;
namespace HopFrame.Core.Services;
public interface ITableManager {
- public IQueryable