Added documentation for the configurators and service extensions methods

This commit is contained in:
2025-01-18 14:48:07 +01:00
parent 9061d878cc
commit 8a55c20f9a
13 changed files with 549 additions and 325 deletions

View File

@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace HopFrame.Core.Config;
public class DbContextConfig {
public Type ContextType { get; }
public List<TableConfig> Tables { get; } = new();
public DbContextConfig(Type context) {
ContextType = context;
foreach (var property in ContextType.GetProperties()) {
if (!property.PropertyType.IsGenericType) continue;
var innerType = property.PropertyType.GenericTypeArguments.First();
var setType = typeof(DbSet<>).MakeGenericType(innerType);
if (property.PropertyType != setType) continue;
var table = new TableConfig(this, innerType, property.Name, Tables.Count);
Tables.Add(table);
}
}
}
public class DbContextConfig<TDbContext>(DbContextConfig config) {
public DbContextConfig InnerConfig { get; } = config;
public DbContextConfig<TDbContext> Table<TModel>(Action<TableConfig<TModel>> configurator) where TModel : class {
var table = Table<TModel>();
configurator.Invoke(table);
return this;
}
public TableConfig<TModel> Table<TModel>() where TModel : class {
var table = InnerConfig.Tables.Single(table => table.TableType == typeof(TModel));
return new TableConfig<TModel>(table);
}
}