模板准备完毕,剩下如何适配生成以后自动生成视图模型和service
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-09-08 21:42:13 +08:00
parent fff6ef5fe2
commit 55e0624dc6
8 changed files with 46 additions and 37 deletions

View File

@ -33,13 +33,13 @@
<ItemGroup> <ItemGroup>
<None Update="Template\EntityService.liquid"> <None Update="LiquidTemplate\EntityService.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="Template\EntityViewModel.liquid"> <None Update="LiquidTemplate\EntityViewModel.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="Template\IEntityService.liquid"> <None Update="LiquidTemplate\IEntityService.liquid">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="TT_Template\IRaCIS .Core.ServiceAsync.tt"> <None Update="TT_Template\IRaCIS .Core.ServiceAsync.tt">
@ -92,11 +92,6 @@
<Folder Include="TT_Template\IServices_New\" /> <Folder Include="TT_Template\IServices_New\" />
<Folder Include="TT_Template\Models_New\" /> <Folder Include="TT_Template\Models_New\" />
<Folder Include="TT_Template\Services_New\" /> <Folder Include="TT_Template\Services_New\" />
<Folder Include="TemplateOutPut\" />
<Folder Include="TemplateOutPut\Entity\" />
<Folder Include="TemplateOutPut\IService\" />
<Folder Include="TemplateOutPut\Service\" />
<Folder Include="TemplateOutPut\ViewModel\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -8,6 +8,9 @@ using IRaCIS.Core.Domain.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Infrastructure.Extention;
using System.Threading.Tasks;
using IRaCIS.Core.Infra.EFCore;
namespace IRaCIS.Core.Application.Service namespace IRaCIS.Core.Application.Service
{ {

View File

@ -4,6 +4,9 @@
// 生成时间 {{DateTimeNow}} // 生成时间 {{DateTimeNow}}
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
//-------------------------------------------------------------------- //--------------------------------------------------------------------
using System;
using IRaCIS.Core.Infrastructure.Extention;
using System.Threading.Tasks;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
namespace IRaCIS.Core.Application.Interfaces namespace IRaCIS.Core.Application.Interfaces
{ {

View File

@ -17,42 +17,46 @@ partial class Program
//发布的目录和项目的目录有区别的 //发布的目录和项目的目录有区别的
var rootPath = AppContext.BaseDirectory.Replace(@"\bin\net8.0\", "").Replace(@"\bin\Release\net8.0\", ""); var rootPath = AppContext.BaseDirectory.Replace(@"\bin\net8.0\", "").Replace(@"\bin\Release\net8.0\", "");
var templateFolderPath = Path.Combine(rootPath, "Template"); var templateFolderPath = Path.Combine(rootPath, "LiquidTemplate");
var outPutTemplateFolderPath = Path.Combine(rootPath, "TemplateOutPut"); var outPutTemplateFolderPath = Path.Combine(rootPath, "LiquidTemplateOutPut");
#region 生成文件目录准备 #region 生成文件目录准备
if (!Directory.Exists(outPutTemplateFolderPath)) if (!Directory.Exists(outPutTemplateFolderPath))
{ {
Directory.CreateDirectory(outPutTemplateFolderPath); Directory.CreateDirectory(outPutTemplateFolderPath);
} }
var servicePath = Path.Combine(outPutTemplateFolderPath, "Service");
var iServicePath = Path.Combine(outPutTemplateFolderPath, "IService");
var entityPath = Path.Combine(outPutTemplateFolderPath, "Entity");
var dtoPath = Path.Combine(outPutTemplateFolderPath, "DTO");
if (!Directory.Exists(servicePath)) #region 废弃 没必要分目录,还是手动设置文件夹
{ //var servicePath = Path.Combine(outPutTemplateFolderPath, "Service");
Directory.CreateDirectory(servicePath); //var iServicePath = Path.Combine(outPutTemplateFolderPath, "IService");
} //var entityPath = Path.Combine(outPutTemplateFolderPath, "Entity");
if (!Directory.Exists(iServicePath)) //var dtoPath = Path.Combine(outPutTemplateFolderPath, "DTO");
{
Directory.CreateDirectory(iServicePath); //if (!Directory.Exists(servicePath))
} //{
if (!Directory.Exists(entityPath)) // Directory.CreateDirectory(servicePath);
{ //}
Directory.CreateDirectory(entityPath); //if (!Directory.Exists(iServicePath))
} //{
if (!Directory.Exists(dtoPath)) // Directory.CreateDirectory(iServicePath);
{ //}
Directory.CreateDirectory(dtoPath); //if (!Directory.Exists(entityPath))
} //{
// Directory.CreateDirectory(entityPath);
//}
//if (!Directory.Exists(dtoPath))
//{
// Directory.CreateDirectory(dtoPath);
//}
#endregion
#endregion #endregion
// 要生成的表名数组 // 要生成的表名数组
var tableNames = new List<string> { /*"Subject", "Order"*/ }; var tableNames = new List<string> { "Subject", "Order" };
try try
{ {
@ -234,7 +238,8 @@ partial class Program
public void CheckCodeFirst() public void CheckCodeFirst()
{ {
var contextOptions = new DbContextOptionsBuilder<IRaCISDBContext>().UseSqlServer(@"Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true").Options; var contextOptions = new DbContextOptionsBuilder<IRaCISDBContext>()
.UseSqlServer(@"Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true").Options;
using var dbContext = new IRaCISDBContext(contextOptions); using var dbContext = new IRaCISDBContext(contextOptions);

View File

@ -32,3 +32,6 @@ Scaffold-DbContext "Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Passw
dotnet ef dbcontext scaffold "Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true" Microsoft.EntityFrameworkCore.SqlServer -p IRaCIS.Core.Test -d -o ModelFolder -c "IRaCISDBContext" -t Subject dotnet ef dbcontext scaffold "Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true" Microsoft.EntityFrameworkCore.SqlServer -p IRaCIS.Core.Test -d -o ModelFolder -c "IRaCISDBContext" -t Subject
开发者PowerShell || 程序包管理控制台命令行 使用:
通过Liquid模板生成基础视图模型、服务接口、服务实现基本方法必须先有数据库实体模型否则视图模型无法生成
dotnet run --project IRaCIS.Core.Test