add support for Dynamic Entity Registration in DbContext by Provides IXEntityRegisterar interface and XBaseEntityRegisterar as an abstract Implementation ...
all other requirements handled inside Module.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using xDataService.Interfaces;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xDataService.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base Entity Registerar ...
|
||||
/// </summary>
|
||||
public abstract class XBaseEntityRegisterar : IXEntityRegisterar
|
||||
{
|
||||
/// <summary>
|
||||
/// Private Entity Types Collection ...
|
||||
/// </summary>
|
||||
private readonly List<Type> entityTypes = [];
|
||||
|
||||
/// <summary>
|
||||
/// Name ...
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
protected XBaseEntityRegisterar(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Entity to Collection ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
public void AddEntity<TEntity, TKey>()
|
||||
where TEntity : XBaseEntity<TKey>
|
||||
{
|
||||
entityTypes.Add(typeof(TEntity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Registered Entity Types ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<Type> GetEntityTypes()
|
||||
{
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Dynamic Entities ...
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder"></param>
|
||||
public virtual void ConfigureEntities(ModelBuilder modelBuilder)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user