HuanMengAdmin/admin-server/MiaoYu.Api.Admin/ApplicationServices/DevelopmentTools/LowCode/Providers/AdminDataSourceProvider.cs
2025-11-08 02:39:31 +08:00

46 lines
1.7 KiB
C#

using HZY.Framework.DependencyInjection.Attributes;
using MiaoYu.Api.Admin.ApplicationServices.DevelopmentTools.LowCode.Abstractions;
namespace MiaoYu.Api.Admin.ApplicationServices.DevelopmentTools.LowCode.Providers;
/// <summary>
/// Admin 数据源提供者
/// </summary>
[Component]
public class AdminDataSourceProvider : IDataSourceProvider, IScopedDependency
{
private readonly IRepository<LowCodeTable> _repository;
public AdminDataSourceProvider(IRepository<LowCodeTable> repository)
{
_repository = repository;
}
public DataSourceConfig Config => new DataSourceConfig
{
DatabaseKey = DataSourceConstants.Admin,
DisplayName = "后台管理系统",
EntityNamespace = typeof(AdminRepositoryStartup).Namespace!,
ModelPathTemplate = "{RootPath}\\{Namespace}\\Entities\\Apps\\{EntityNamePlural}",
ServicePathTemplate = "{AppPath}\\ApplicationServices\\Apps\\{EntityNamePlural}",
ControllerPathTemplate = "{AppPath}\\Controllers\\Apps\\{EntityNamePlural}",
ClientIndexPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\{TableName}s",
ClientInfoPathTemplate = "{RootPath}\\admin-client\\src\\views\\apps\\{TableName}s",
ClientServicePathTemplate = "{RootPath}\\admin-client\\src\\services\\apps\\{TableName}s",
TemplatePath = "/wwwroot/code_generation/template/",
NamingStrategy = EntityNamingStrategy.ToPascalCase,
Order = 1,
EnableEntityPrefix = false,
EntityPrefix = "",
UsesPluralPath = true
};
public List<DbTableInfo> GetTables()
{
return _repository.UnitOfWork.FreeSqlOrm.DbFirst.GetTablesByDatabase();
}
public DbContext GetDbContext() => _repository.GetContext()!;
}