feat(cli): add ms microservice template support
1. 新增`ms`微服务模板,包含共享项目、微服务、网关、应用等完整架构 2. 为`hua new`命令添加`ms`模板选项并更新文档 3. 将模板文件嵌入CLI项目输出目录 4. 实现微服务模板的项目构建逻辑,自动安装并使用dotnet自定义模板创建项目
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Company.Project.Shared;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Account;
|
||||
using Volo.Abp.Account.Web;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.BasicTheme;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore.SqlServer;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Identity.EntityFrameworkCore;
|
||||
using Volo.Abp.IdentityServer.EntityFrameworkCore;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.TenantManagement.EntityFrameworkCore;
|
||||
|
||||
namespace Company.Project.AuthServer;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
|
||||
typeof(AbpIdentityEntityFrameworkCoreModule),
|
||||
typeof(AbpIdentityApplicationModule),
|
||||
typeof(AbpIdentityServerEntityFrameworkCoreModule),
|
||||
typeof(AbpAccountWebIdentityServerModule),
|
||||
typeof(AbpTenantManagementEntityFrameworkCoreModule)
|
||||
)]
|
||||
public class AuthServerHostModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpMultiTenancyOptions>(options =>
|
||||
{
|
||||
options.IsEnabled = ProjectConsts.IsMultiTenancyEnabled;
|
||||
});
|
||||
|
||||
Configure<AbpDbContextOptions>(options => options.UseSqlServer());
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
var app = context.GetApplicationBuilder();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseIdentityServer();
|
||||
app.UseConfiguredEndpoints();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>Company.Project.AuthServer</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Identity.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.IdentityServer.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<ProjectReference Include="..\..\shared\Company.Project.Shared\Company.Project.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace Company.Project.AuthServer;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
|
||||
try { CreateHostBuilder(args).Build().Run(); }
|
||||
catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); }
|
||||
finally { Log.CloseAndFlush(); }
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseAutofac().UseSerilog()
|
||||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Company.Project.AuthServer;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddApplication<AuthServerHostModule>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostEnvironment env)
|
||||
{
|
||||
app.InitializeApplication();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=Company.Project_AuthServer;Trusted_Connection=True"
|
||||
},
|
||||
"Serilog": { "MinimumLevel": { "Default": "Information" } },
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using Company.Project.Shared;
|
||||
using ProductManagement;
|
||||
using ProductManagement.Web;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.AspNetCore.Mvc.Client;
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.BasicTheme;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Http.Client.IdentityModel.Web;
|
||||
using Volo.Abp.Identity.Web;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.TenantManagement.Web;
|
||||
|
||||
namespace Company.Project.BackendAdminApp;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpAspNetCoreMvcClientModule),
|
||||
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
|
||||
typeof(AbpHttpClientIdentityModelWebModule),
|
||||
typeof(AbpIdentityWebModule),
|
||||
typeof(AbpTenantManagementWebModule),
|
||||
typeof(ProductManagementHttpApiClientModule),
|
||||
typeof(ProductManagementWebModule)
|
||||
)]
|
||||
public class BackendAdminAppHostModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpMultiTenancyOptions>(options =>
|
||||
{
|
||||
options.IsEnabled = ProjectConsts.IsMultiTenancyEnabled;
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
var app = context.GetApplicationBuilder();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseConfiguredEndpoints();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>Company.Project.BackendAdminApp</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.Client" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Http.Client.IdentityModel.Web" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Identity.Web" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Web" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<ProjectReference Include="..\..\shared\Company.Project.Shared\Company.Project.Shared.csproj" />
|
||||
<ProjectReference Include="..\..\modules\product\src\ProductManagement.HttpApi.Client\ProductManagement.HttpApi.Client.csproj" />
|
||||
<ProjectReference Include="..\..\modules\product\src\ProductManagement.Web\ProductManagement.Web.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace Company.Project.BackendAdminApp;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
|
||||
try { CreateHostBuilder(args).Build().Run(); }
|
||||
catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); }
|
||||
finally { Log.CloseAndFlush(); }
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.UseAutofac().UseSerilog()
|
||||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Company.Project.BackendAdminApp;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddApplication<BackendAdminAppHostModule>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostEnvironment env)
|
||||
{
|
||||
app.InitializeApplication();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user