From 77bacd2f4c9ba2286078e6a65b33e0a75e95ef6b Mon Sep 17 00:00:00 2001 From: feijie Date: Mon, 30 Dec 2024 00:27:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(=E5=BE=AE=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF):=20=E6=B7=BB=E5=8A=A0=20Abp=20=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E5=BE=AE=E6=9C=8D=E5=8A=A1=E6=A8=A1=E6=9D=BF=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=96=87=E4=BB=B6=20PackageName.CompanyName.ProjectNa?= =?UTF-8?q?me.csproj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...PackageName.CompanyName.ProjectName.csproj | 30 ++ .../content/.template.config/template.json | 116 +++++ .../.template.config/template.zh-Hans.json | 5 + .../micro/content/Directory.Build.props | 13 + .../micro/content/Directory.Packages.props | 490 ++++++++++++++++++ .../templates/micro/content/NuGet.Config | 12 + aspnet-core/templates/micro/content/README.md | 129 +++++ .../templates/micro/content/README.zh-CN.md | 129 +++++ .../templates/micro/content/common.props | 38 ++ .../micro/content/configureawait.props | 9 + .../DbMigratorHostedService.cs | 53 ++ .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ....CompanyName.ProjectName.DbMigrator.csproj | 42 ++ ...eCompanyNameProjectNameDbMigratorModule.cs | 13 + .../Program.cs | 40 ++ .../appsettings.Development.json | 147 ++++++ .../appsettings.json | 80 +++ .../Controllers/HomeController.cs | 12 + .../Dockerfile | 57 ++ ...ompanyName.ProjectName.HttpApi.Host.csproj | 76 +++ .../Program.cs | 65 +++ .../ProjectNameHttpApiHostModule.Configure.cs | 445 ++++++++++++++++ .../ProjectNameHttpApiHostModule.cs | 127 +++++ .../Properties/launchSettings.json | 28 + .../TenantHeaderParamter.cs | 31 ++ .../appsettings.Development.json | 153 ++++++ .../appsettings.json | 88 ++++ .../dapr.sh | 1 + .../generate-proxy.sh | 2 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...e.ProjectName.Application.Contracts.csproj | 27 + .../ProjectNameFeatureDefinitionProvider.cs | 18 + .../Features/ProjectNameFeatureNames.cs | 6 + .../IProjectNameDynamicQueryableAppService.cs | 10 + ...ProjectNamePermissionDefinitionProvider.cs | 22 + .../Permissions/ProjectNamePermissions.cs | 8 + .../ProjectNameApplicationContractsModule.cs | 17 + .../ProjectNameRemoteServiceConsts.cs | 7 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...CompanyName.ProjectName.Application.csproj | 26 + .../ProjectName/ProjectNameAppServiceBase.cs | 13 + .../ProjectNameApplicationMapperProfile.cs | 10 + .../ProjectNameApplicationModule.cs | 27 + ...ojectNameDynamicQueryableAppServiceBase.cs | 19 + .../Expressions/ExpressionFuncExtensions.cs | 32 ++ .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...CompanyName.ProjectName.Dapr.Client.csproj | 19 + .../ProjectNameDaprClientModule.cs | 18 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...mpanyName.ProjectName.Domain.Shared.csproj | 30 ++ .../Localization/ProjectNameResource.cs | 8 + .../Localization/Resources/en.json | 8 + .../Localization/Resources/zh-Hans.json | 8 + ...ProjectNameModuleExtensionConfiguration.cs | 16 + ...ensionConfigurationDictionaryExtensions.cs | 19 + .../ProjectNameModuleExtensionConsts.cs | 11 + .../ProjectNameDomainSharedModule.cs | 32 ++ .../ProjectName/ProjectNameErrorCodes.cs | 6 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...Name.CompanyName.ProjectName.Domain.csproj | 27 + .../IProjectNameBasicRepository.cs | 54 ++ .../ProjectName/ProjectNameDbProperties.cs | 11 + .../ProjectNameDomainMapperProfile.cs | 11 + .../ProjectName/ProjectNameDomainModule.cs | 45 ++ .../ProjectNameSettingDefinitionProvider.cs | 10 + .../Settings/ProjectNameSettings.cs | 6 + .../Expressions/ExpressionFuncExtensions.cs | 32 ++ .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...ame.ProjectName.EntityFrameworkCore.csproj | 37 ++ .../EfCoreProjectNameRepository.cs | 77 +++ .../IProjectNameDbContext.cs | 9 + .../ProjectNameDbContext.cs | 21 + .../ProjectNameDbContextFactory.cs | 49 ++ ...ectNameDbContextModelCreatingExtensions.cs | 21 + .../ProjectNameDbMigrationEventHandler.cs | 36 ++ .../ProjectNameDbMigrationService.cs | 58 +++ .../ProjectNameEfCoreQueryableExtensions.cs | 6 + .../ProjectNameEntityFrameworkCoreModule.cs | 76 +++ ...ectNameModelBuilderConfigurationOptions.cs | 17 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...panyName.ProjectName.HttpApi.Client.csproj | 24 + .../ProjectNameHttpApiClientModule.cs | 18 + .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...ame.CompanyName.ProjectName.HttpApi.csproj | 25 + .../ProjectName/ProjectNameControllerBase.cs | 12 + ...ojectNameDynamicQueryableControllerBase.cs | 17 + .../ProjectName/ProjectNameHttpApiModule.cs | 42 ++ .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++ ...yName.ProjectName.SettingManagement.csproj | 27 + .../IProjectNameSettingAppService.cs | 7 + .../ProjectNameSettingAppService.cs | 106 ++++ .../ProjectNameSettingController.cs | 69 +++ .../ProjectNameSettingManagementModule.cs | 22 + ...yName.ProjectName.Application.Tests.csproj | 18 + .../ProjectNameApplicationTestBase.cs | 5 + .../ProjectNameApplicationTestModule.cs | 11 + ...ompanyName.ProjectName.Domain.Tests.csproj | 18 + .../ProjectName/ProjectNameDomainTestBase.cs | 5 + .../ProjectNameDomainTestModule.cs | 11 + ...ojectName.EntityFrameworkCore.Tests.csproj | 19 + .../ProjectNameEntityFrameworkCoreTestBase.cs | 5 + ...rojectNameEntityFrameworkCoreTestModule.cs | 38 ++ ...me.CompanyName.ProjectName.TestBase.csproj | 23 + .../ProjectName/ProjectNameTestBase.cs | 58 +++ .../ProjectName/ProjectNameTestBaseModule.cs | 24 + 115 files changed, 4385 insertions(+) create mode 100644 aspnet-core/templates/micro/PackageName.CompanyName.ProjectName.csproj create mode 100644 aspnet-core/templates/micro/content/.template.config/template.json create mode 100644 aspnet-core/templates/micro/content/.template.config/template.zh-Hans.json create mode 100644 aspnet-core/templates/micro/content/Directory.Build.props create mode 100644 aspnet-core/templates/micro/content/Directory.Packages.props create mode 100644 aspnet-core/templates/micro/content/NuGet.Config create mode 100644 aspnet-core/templates/micro/content/README.md create mode 100644 aspnet-core/templates/micro/content/README.zh-CN.md create mode 100644 aspnet-core/templates/micro/content/common.props create mode 100644 aspnet-core/templates/micro/content/configureawait.props create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/DbMigratorHostedService.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageNameCompanyNameProjectNameDbMigratorModule.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.Development.json create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.json create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Controllers/HomeController.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Dockerfile create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Program.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.Configure.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Properties/launchSettings.json create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/TenantHeaderParamter.cs create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.json create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/dapr.sh create mode 100644 aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/generate-proxy.sh create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName.CompanyName.ProjectName.Application.Contracts.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/IProjectNameDynamicQueryableAppService.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissionDefinitionProvider.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameApplicationContractsModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameRemoteServiceConsts.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName.CompanyName.ProjectName.Application.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameAppServiceBase.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationMapperProfile.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableAppServiceBase.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/System/Linq/Expressions/ExpressionFuncExtensions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName.CompanyName.ProjectName.Dapr.Client.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName/CompanyName/ProjectName/ProjectNameDaprClientModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName.CompanyName.ProjectName.Domain.Shared.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/ProjectNameResource.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/en.json create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/zh-Hans.json create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfiguration.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfigurationDictionaryExtensions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConsts.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameDomainSharedModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameErrorCodes.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName.CompanyName.ProjectName.Domain.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/IProjectNameBasicRepository.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDbProperties.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainMapperProfile.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettingDefinitionProvider.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettings.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName.CompanyName.ProjectName.EntityFrameworkCore.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/EfCoreProjectNameRepository.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/IProjectNameDbContext.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContext.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextFactory.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextModelCreatingExtensions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEfCoreQueryableExtensions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameModelBuilderConfigurationOptions.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName.CompanyName.ProjectName.HttpApi.Client.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName/CompanyName/ProjectName/ProjectNameHttpApiClientModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName.CompanyName.ProjectName.HttpApi.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameControllerBase.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableControllerBase.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameHttpApiModule.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xml create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xsd create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName.CompanyName.ProjectName.SettingManagement.csproj create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/IProjectNameSettingAppService.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingAppService.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingController.cs create mode 100644 aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingManagementModule.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName.CompanyName.ProjectName.Application.Tests.csproj create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestBase.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestModule.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName.CompanyName.ProjectName.Domain.Tests.csproj create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestBase.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestModule.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests.csproj create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestBase.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestModule.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName.CompanyName.ProjectName.TestBase.csproj create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBase.cs create mode 100644 aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBaseModule.cs diff --git a/aspnet-core/templates/micro/PackageName.CompanyName.ProjectName.csproj b/aspnet-core/templates/micro/PackageName.CompanyName.ProjectName.csproj new file mode 100644 index 000000000..cceabf72e --- /dev/null +++ b/aspnet-core/templates/micro/PackageName.CompanyName.ProjectName.csproj @@ -0,0 +1,30 @@ + + + net8.0 + true + LINGYUN.Abp.MicroService.Templates + 8.3.0 + colin.in@foxmail.com + Abp framework micro-service template + MIT + false + https://github.com/colinin/abp-next-admin + micro webapi cloud + Template + git + https://github.com/colinin/abp-next-admin + true + true + true + true + False + False + + + + + true + content + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/.template.config/template.json b/aspnet-core/templates/micro/content/.template.config/template.json new file mode 100644 index 000000000..d57640554 --- /dev/null +++ b/aspnet-core/templates/micro/content/.template.config/template.json @@ -0,0 +1,116 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "colin.in@foxmail.com", + "classifications": ["micro", "webapi", "cloud"], + "name": "LINGYUN.Abp.MicroService", + "identity": "LINGYUN.Abp.MicroService", + "description": "Abp framework micro-service template", + "groupIdentity": "LINGYUN.Abp.Application", + "shortName": "lam", + "tags": { + "language": "C#", + "type": "project" + }, + "sources": [ + { + "modifiers": [ + { + "exclude": [ + "**/[Bb]in/**", + "**/[Oo]bj/**", + "**/[Ll]ocalNuget/**", + ".template.config/**/*", + ".vs/**/*", + "**/host/PackageName.CompanyName.ProjectName.AIO.Host/**" + ] + } + ] + } + ], + "sourceName": "ProjectName", + "preferNameDirectory": true, + "symbols": { + "AuthenticationScheme": { + "type": "parameter", + "description": "Authentication Scheme", + "datatype": "choice", + "defaultValue": "IdentityServer4", + "isRequired": false, + "choices": [ + { + "choice": "IdentityServer4", + "description": "IdentityServer4" + }, + { + "choice": "OpenIddict", + "description": "OpenIddict" + } + ] + }, + "DatabaseManagement": { + "type": "parameter", + "description": "Database Management", + "dataType": "choice", + "defaultValue": "MySQL", + "isRequired": false, + "choices": [ + { + "choice": "SqlServer", + "description": "Sql Server" + }, + { + "choice": "MySQL", + "description": "My SQL" + }, + { + "choice": "Sqlite", + "description": "Sqlite" + }, + { + "choice": "Oracle", + "description": "Oracle" + }, + { + "choice": "OracleDevart", + "description": "Oracle Devart Driver" + }, + { + "choice": "PostgreSql", + "description": "Postgre Sql" + } + ] + }, + "SqlServer": { + "type": "computed", + "value": "(DatabaseManagement == \"SqlServer\")" + }, + "MySQL": { + "type": "computed", + "value": "(DatabaseManagement == \"MySQL\")" + }, + "Sqlite": { + "type": "computed", + "value": "(DatabaseManagement == \"Sqlite\")" + }, + "Oracle": { + "type": "computed", + "value": "(DatabaseManagement == \"Oracle\")" + }, + "OracleDevart": { + "type": "computed", + "value": "(DatabaseManagement == \"Oracle.Devart\")" + }, + "PostgreSql": { + "type": "computed", + "value": "(DatabaseManagement == \"PostgreSql\")" + }, + "IdentityServer4": { + "type": "computed", + "value": "(AuthenticationScheme == \"IdentityServer4\")" + }, + "OpenIddict": { + "type": "computed", + "value": "(AuthenticationScheme == \"OpenIddict\")" + } + } +} diff --git a/aspnet-core/templates/micro/content/.template.config/template.zh-Hans.json b/aspnet-core/templates/micro/content/.template.config/template.zh-Hans.json new file mode 100644 index 000000000..f0339e4e4 --- /dev/null +++ b/aspnet-core/templates/micro/content/.template.config/template.zh-Hans.json @@ -0,0 +1,5 @@ +{ + "description": "适用于abp框架的微服务模板项目", + "symbols/AuthenticationScheme/description": "认证服务体系, 可选项为: IdentityServer4、OpenIddict, 默认使用IdentityServer4.", + "symbols/DatabaseManagement/description": "数据库管理提供者, 可选项为: SqlServer、MySQL、Sqlite、Oracle、OracleDevart、PostgreSql, 默认使用MySQL." +} diff --git a/aspnet-core/templates/micro/content/Directory.Build.props b/aspnet-core/templates/micro/content/Directory.Build.props new file mode 100644 index 000000000..6f2501679 --- /dev/null +++ b/aspnet-core/templates/micro/content/Directory.Build.props @@ -0,0 +1,13 @@ + + + true + + + + + all + runtime; build; native; contentfiles; analyzers + + + + diff --git a/aspnet-core/templates/micro/content/Directory.Packages.props b/aspnet-core/templates/micro/content/Directory.Packages.props new file mode 100644 index 000000000..433f06afb --- /dev/null +++ b/aspnet-core/templates/micro/content/Directory.Packages.props @@ -0,0 +1,490 @@ + + + 8.2.0 + 2.14.1 + 8.3.0 + 8.3.0 + 8.0.0 + 8.0.0 + 8.0.0 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/NuGet.Config b/aspnet-core/templates/micro/content/NuGet.Config new file mode 100644 index 000000000..ddde6944c --- /dev/null +++ b/aspnet-core/templates/micro/content/NuGet.Config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/README.md b/aspnet-core/templates/micro/content/README.md new file mode 100644 index 000000000..7b7520aef --- /dev/null +++ b/aspnet-core/templates/micro/content/README.md @@ -0,0 +1,129 @@ +# LINGYUN.Abp.Templates + +[English](README.md) | [中文](README.zh-CN.md) + +## Introduction + +LINGYUN.Abp.Templates provides two types of project templates based on ABP Framework: + +1. **Microservice Template**: A complete microservice architecture template with distributed services. +2. **All-in-One Template**: A single-application template that combines all services into one project. + +## Features + +### Common Features + +- Integrated authentication (IdentityServer4/OpenIddict) +- Database integration (multiple databases supported) +- Unified configuration management +- Distributed event bus support +- Background job processing + +### Microservice Template Features + +- Complete microservice project structure +- Service discovery and registration +- Distributed deployment support + +### All-in-One Template Features + +- Simplified deployment +- Easier maintenance +- Lower resource requirements + +## How to Use + +### Install Templates + +```bash +# Install Microservice Template +dotnet new install LINGYUN.Abp.MicroService.Templates + +# Install All-in-One Template +dotnet new install LINGYUN.Abp.AllInOne.Templates +``` + +### Create New Project + +#### For Microservice Project + +```bash +# Short name: lam (LINGYUN Abp Microservice) +dotnet new lam -n YourCompanyName.YourProjectName -pk YourPackageName -o /path/to/output --dbms MySql --cs "Server=127.0.0.1;Database=YourDatabase;User Id=your_user;Password=your_password;SslMode=None" --no-random-port +``` + +#### For All-in-One Project + +```bash +# Short name: laa (LINGYUN Abp AllInOne) +dotnet new laa -n YourCompanyName.YourProjectName -pk YourPackageName -o /path/to/output --dbms MySql --cs "Server=127.0.0.1;Database=YourDatabase;User Id=your_user;Password=your_password;SslMode=None" --no-random-port +``` + +## How to Run + +After creating your project, you can run it using the following command: + +### For Microservice Project + +```bash +cd /path/to/output/host/YourPackageName.YourCompanyName.YourProjectName.HttpApi.Host +dotnet run --launch-profile "YourPackageName.YourCompanyName.YourProjectName.Development" +``` + +### For All-in-One Project + +```bash +cd /path/to/output/host/YourPackageName.YourCompanyName.YourProjectName.AIO.Host +dotnet run --launch-profile "YourPackageName.YourCompanyName.YourProjectName.Development" +``` + +## How to Package and Publish + +1. Clone the Project + +```bash +git clone +cd /aspnet-core/templates/content +``` + +2. Modify Version + Edit the project files to update versions: + - For Microservice: `../PackageName.CompanyName.ProjectName.csproj` + - For All-in-One: `../PackageName.CompanyName.ProjectName.AIO.csproj` + +```xml +8.3.0 +``` + +3. Execute Packaging Script + +```powershell +# Windows PowerShell +.\pack.ps1 + +# PowerShell Core (Windows/Linux/macOS) +pwsh pack.ps1 +``` + +The script will prompt you to choose which template to package: + +1. Microservice Template +2. All-in-One Template +3. Both Templates + +## Supported Databases + +- SqlServer +- MySQL +- PostgreSQL +- Oracle +- SQLite + +## Notes + +- Ensure .NET SDK 8.0 or higher is installed +- Choose the appropriate template based on your needs: + - Microservice Template: For large-scale distributed applications + - All-in-One Template: For smaller applications or simpler deployment requirements +- Pay attention to NuGet publish address and key when packaging +- Complete testing is recommended before publishing diff --git a/aspnet-core/templates/micro/content/README.zh-CN.md b/aspnet-core/templates/micro/content/README.zh-CN.md new file mode 100644 index 000000000..b93d76220 --- /dev/null +++ b/aspnet-core/templates/micro/content/README.zh-CN.md @@ -0,0 +1,129 @@ +# LINGYUN.Abp.Templates + +[English](README.md) | [中文](README.zh-CN.md) + +## 简介 + +LINGYUN.Abp.Templates 基于 ABP Framework 提供两种项目模板: + +1. **微服务模板**:完整的分布式微服务架构模板 +2. **单体应用模板**:将所有服务集成到一个项目中的单体应用模板 + +## 特性 + +### 共同特性 + +- 集成身份认证(支持 IdentityServer4/OpenIddict) +- 数据库集成(支持多种数据库) +- 统一配置管理 +- 分布式事件总线支持 +- 后台作业处理 + +### 微服务模板特性 + +- 完整的微服务项目结构 +- 服务发现与注册 +- 支持分布式部署 + +### 单体应用模板特性 + +- 简化的部署流程 +- 更容易的维护 +- 更低的资源需求 + +## 使用方法 + +### 安装模板 + +```bash +# 安装微服务模板 +dotnet new install LINGYUN.Abp.MicroService.Templates + +# 安装单体应用模板 +dotnet new install LINGYUN.Abp.AllInOne.Templates +``` + +### 创建新项目 + +#### 创建微服务项目 + +```bash +# 简写名称:lam (LINGYUN Abp Microservice) +dotnet new lam -n YourCompanyName.YourProjectName -pk YourPackageName -o /path/to/output --dbms MySql --cs "Server=127.0.0.1;Database=YourDatabase;User Id=your_user;Password=your_password;SslMode=None" --no-random-port +``` + +#### 创建单体应用项目 + +```bash +# 简写名称:laa (LINGYUN Abp AllInOne) +labp create MyCompanyName.MyProjectName -pk MyPackageName -t laa -o /Users/feijie/Projects/Tests --dbms MySql --cs "Server=127.0.0.1;Database=Platform-V70;User Id=root;Password=123456;SslMode=None" --no-random-port +``` + +## 运行项目 + +创建项目后,可以使用以下命令运行: + +### 运行微服务项目 + +```bash +cd /path/to/output/host/YourPackageName.YourCompanyName.YourProjectName.HttpApi.Host +dotnet run --launch-profile "YourPackageName.YourCompanyName.YourProjectName.Development" +``` + +### 运行单体应用项目 + +```bash +cd /path/to/output/host/YourPackageName.YourCompanyName.YourProjectName.AIO.Host +dotnet run --launch-profile "YourPackageName.YourCompanyName.YourProjectName.Development" +``` + +## 打包与发布 + +1. 克隆项目 + +```bash +git clone +cd /aspnet-core/templates/content +``` + +2. 修改版本号 + 编辑项目文件更新版本号: + - 微服务模板:`../PackageName.CompanyName.ProjectName.csproj` + - 单体应用模板:`../PackageName.CompanyName.ProjectName.AIO.csproj` + +```xml +8.3.0 +``` + +3. 执行打包脚本 + +```powershell +# Windows PowerShell +.\pack.ps1 + +# PowerShell Core (Windows/Linux/macOS) +pwsh pack.ps1 +``` + +脚本会提示您选择要打包的模板: + +1. 微服务模板 +2. 单体应用模板 +3. 两种模板都打包 + +## 支持的数据库 + +- SqlServer +- MySQL +- PostgreSQL +- Oracle +- SQLite + +## 注意事项 + +- 确保已安装 .NET SDK 8.0 或更高版本 +- 根据需求选择合适的模板: + - 微服务模板:适用于大规模分布式应用 + - 单体应用模板:适用于小型应用或简单部署需求 +- 打包时注意 NuGet 发布地址和密钥 +- 发布前建议进行完整测试 diff --git a/aspnet-core/templates/micro/content/common.props b/aspnet-core/templates/micro/content/common.props new file mode 100644 index 000000000..d7d7622cf --- /dev/null +++ b/aspnet-core/templates/micro/content/common.props @@ -0,0 +1,38 @@ + + + latest + 8.2.1 + colin + $(NoWarn);CS1591;CS0436;CS8618;NU1803 + https://github.com/colinin/abp-next-admin + $(SolutionDir)LocalNuget + 8.2.1 + MIT + git + https://github.com/colinin/abp-next-admin + true + + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)LocalNuget + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/configureawait.props b/aspnet-core/templates/micro/content/configureawait.props new file mode 100644 index 000000000..3caa88c04 --- /dev/null +++ b/aspnet-core/templates/micro/content/configureawait.props @@ -0,0 +1,9 @@ + + + + + All + runtime; build; native; contentfiles; analyzers + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/DbMigratorHostedService.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 000000000..d279fb30f --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using PackageName.CompanyName.ProjectName.EntityFrameworkCore; +using Serilog; +using Volo.Abp; +using Volo.Abp.Data; + +namespace PackageName.CompanyName.ProjectName.DbMigrator; + +public class DbMigratorHostedService : IHostedService +{ + private readonly IHostApplicationLifetime _hostApplicationLifetime; + private readonly IConfiguration _configuration; + + public DbMigratorHostedService( + IHostApplicationLifetime hostApplicationLifetime, + IConfiguration configuration) + { + _hostApplicationLifetime = hostApplicationLifetime; + _configuration = configuration; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + using var application = await AbpApplicationFactory + .CreateAsync(options => + { + options.Configuration.UserSecretsId = Environment.GetEnvironmentVariable("APPLICATION_USER_SECRETS_ID"); + options.Configuration.UserSecretsAssembly = typeof(DbMigratorHostedService).Assembly; + options.Services.ReplaceConfiguration(_configuration); + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + options.AddDataMigrationEnvironment(); + }); + await application.InitializeAsync(); + + await application + .ServiceProvider + .GetRequiredService() + .CheckAndApplyDatabaseMigrationsAsync(); + + await application.ShutdownAsync(); + + _hostApplicationLifetime.StopApplication(); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } +} + diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xml b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xsd b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj new file mode 100644 index 000000000..4d69cfc5b --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj @@ -0,0 +1,42 @@ + + + + + + + Exe + net8.0 + enable + enable + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageNameCompanyNameProjectNameDbMigratorModule.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageNameCompanyNameProjectNameDbMigratorModule.cs new file mode 100644 index 000000000..fd08046e4 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageNameCompanyNameProjectNameDbMigratorModule.cs @@ -0,0 +1,13 @@ +using PackageName.CompanyName.ProjectName.EntityFrameworkCore; +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName.DbMigrator; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(ProjectNameEntityFrameworkCoreModule) + )] +public class PackageNameCompanyNameProjectNameDbMigratorModule : AbpModule +{ +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs new file mode 100644 index 000000000..e4739face --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Events; + +namespace PackageName.CompanyName.ProjectName.DbMigrator; + +public class Program +{ + public async static Task Main(string[] args) + { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning) +#if DEBUG + .MinimumLevel.Override("PackageName.CompanyName.ProjectName", LogEventLevel.Debug) +#else + .MinimumLevel.Override("PackageName.CompanyName.ProjectName", LogEventLevel.Information) +#endif + .Enrich.FromLogContext() + .WriteTo.File("Logs/logs.txt") + .WriteTo.Console() + .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) + { + return Host.CreateDefaultBuilder(args) + .AddAppSettingsSecretsJson() + .ConfigureLogging((context, logging) => logging.ClearProviders()) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.Development.json b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.Development.json new file mode 100644 index 000000000..19ddebe12 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.Development.json @@ -0,0 +1,147 @@ +{ + "AgileConfig": { + "IsEnabled": false, + "env": "DEV", + "appId": "PackageName.CompanyName.ProjectName", + "secret": "1q2w3E*", + "nodes": "http://127.0.0.1:15000", + "name": "PackageName.CompanyName.ProjectName", + "tag": "PackageName.CompanyName.ProjectName" + }, + "Auditing": { + "AllEntitiesSelector": true + }, + "DistributedCache": { + "HideErrors": true, + "KeyPrefix": "LINGYUN.Abp.Application", + "GlobalCacheEntryOptions": { + "SlidingExpiration": "30:00:00", + "AbsoluteExpirationRelativeToNow": "60:00:00" + } + }, + "ConnectionStrings": { + "Default": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "ProjectName": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpSaas": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpFeatureManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpPermissionManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpSettingManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpLocalizationManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpTextTemplating": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "DistributedLock": { + "IsEnabled": true, + "Redis": { + "Configuration": "127.0.0.1,defaultDatabase=15" + } + }, + "OpenTelemetry": { + "IsEnabled": true, + "ZipKin": { + "Endpoint": "http://127.0.0.1:9411/api/v2/spans" + } + }, + "RemoteServices": {}, + "IdentityClients": { + "InternalServiceClient": { + "Authority": "http://127.0.0.1:44385", + "RequireHttps": false, + "GrantType": "client_credentials", + "Scope": "lingyun-abp-application", + "ClientId": "InternalServiceClient", + "ClientSecret": "1q2w3E*" + } + }, + "CAP": { + "EventBus": { + "DefaultGroupName": "ProjectName", + "GroupNamePrefix": "Dev", + "Version": "v1", + "FailedRetryInterval": 300, + "FailedRetryCount": 10 + }, + "MySql": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "SqlServer": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "Sqlite": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Data Source=./cap.db" + }, + "Oracle": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Data Source=ProjectName;Integrated Security=yes;" + }, + "PostgreSql": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Host=localhost;Port=5432;Database=ProjectName;User ID=root;Password=123456;" + }, + "RabbitMQ": { + "HostName": "127.0.0.1", + "Port": 5672, + "UserName": "admin", + "Password": "123456", + "ExchangeName": "LINGYUN.Abp.Application", + "VirtualHost": "/" + } + }, + "Redis": { + "Configuration": "127.0.0.1,defaultDatabase=10", + "InstanceName": "LINGYUN.Abp.Application" + }, + "AuthServer": { + "Authority": "http://127.0.0.1:44385/", + "Audience": "lingyun-abp-application", + "MapInboundClaims": false, + "RequireHttpsMetadata": false, + "SwaggerClientId": "InternalServiceClient", + "SwaggerClientSecret": "1q2w3E*" + }, + "Logging": { + "Serilog": { + "Elasticsearch": { + "IndexFormat": "abp.dev.logging-{0:yyyy.MM.dd}" + } + } + }, + "AuditLogging": { + "Elasticsearch": { + "IndexPrefix": "abp.dev.auditing" + } + }, + "Elasticsearch": { + "NodeUris": "http://127.0.0.1:9200" + }, + "Serilog": { + "MinimumLevel": { + "Default": "Debug", + "Override": { + "System": "Warning", + "Microsoft": "Warning", + "DotNetCore": "Debug" + } + }, + "WriteTo": [ + { + "Name": "Console", + "Args": { + "restrictedToMinimumLevel": "Debug", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "Elasticsearch", + "Args": { + "nodeUris": "http://127.0.0.1:9200", + "indexFormat": "abp.dev.logging-{0:yyyy.MM.dd}", + "autoRegisterTemplate": true, + "autoRegisterTemplateVersion": "ESv7" + } + } + ] + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.json b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.json new file mode 100644 index 000000000..2f919b2c2 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/appsettings.json @@ -0,0 +1,80 @@ +{ + "StringEncryption": { + "DefaultPassPhrase": "s46c5q55nxpeS8Ra", + "InitVectorBytes": "s83ng0abvd02js84", + "DefaultSalt": "sf&5)s3#" + }, + "AllowedHosts": "*", + "Serilog": { + "MinimumLevel": { + "Default": "Debug", + "Override": { + "Microsoft.EntityFrameworkCore": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName", "WithUniqueId" ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "initialMinimumLevel": "Verbose", + "standardErrorFromLevel": "Verbose", + "restrictedToMinimumLevel": "Verbose", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Debug-.log", + "restrictedToMinimumLevel": "Debug", + "rollingInterval": "Day", + "fileSizeLimitBytes": 5242880, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Info-.log", + "restrictedToMinimumLevel": "Information", + "rollingInterval": "Day", + "fileSizeLimitBytes": 5242880, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Warn-.log", + "restrictedToMinimumLevel": "Warning", + "rollingInterval": "Day", + "fileSizeLimitBytes": 5242880, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Error-.log", + "restrictedToMinimumLevel": "Error", + "rollingInterval": "Day", + "fileSizeLimitBytes": 5242880, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Fatal-.log", + "restrictedToMinimumLevel": "Fatal", + "rollingInterval": "Day", + "fileSizeLimitBytes": 5242880, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + } + ] + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Controllers/HomeController.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Controllers/HomeController.cs new file mode 100644 index 000000000..5e1bb362a --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Controllers/HomeController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace PackageName.CompanyName.ProjectName.Controllers; + +public class HomeController : AbpController +{ + public IActionResult Index() + { + return Redirect("/swagger/index.html"); + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Dockerfile b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Dockerfile new file mode 100644 index 000000000..012ce3615 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Dockerfile @@ -0,0 +1,57 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +LABEL maintainer="colin.in@foxmail.com" +WORKDIR /app + +COPY . /app + +## 设置服务器时区. +## 建议在外部(如docker-compose.yml)中定义 +## Set server time zone. +## Suggest defining it externally (such as Docker Compose. yml) +#ENV TZ=Asia/Shanghai +#RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone + + +## 解决连接SqlServer TLS版本过高问题. +## 如果数据提供者是SqlServer, 且兼容性版本在120及以下,需要手动取消注释. +## The version of connection SqlServer TLS is too high. +## If the data provider is SqlServer and the compatibility version is 120 and below, manual annotation needs to be cancelled. + +#RUN sed -i 's/\[openssl_init\]/# \[openssl_init\]/g' /etc/ssl/openssl.cnf +#RUN sed -i '$a\[openssl_init]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\providers = provider_sect' /etc/ssl/openssl.cnf +#RUN sed -i '$a\ssl_conf = ssl_sect' /etc/ssl/openssl.cnf + # +#RUN sed -i '$a\[provider_sect]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\default = default_sect' /etc/ssl/openssl.cnf +#RUN sed -i '$a\legacy = legacy_sect' /etc/ssl/openssl.cnf + # +#RUN sed -i '$a\[default_sect]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\activate = 1' /etc/ssl/openssl.cnf + # +#RUN sed -i '$a\[legacy_sect]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\activate = 1' /etc/ssl/openssl.cnf + # +#RUN sed -i '$a\[ssl_sect]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\system_default = system_default_sect' /etc/ssl/openssl.cnf + # +#RUN sed -i '$a\[system_default_sect]' /etc/ssl/openssl.cnf +#RUN sed -i '$a\CipherString = DEFAULT:@SECLEVEL=0' /etc/ssl/openssl.cnf + +## 阿里源 +#RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/debian.sources +#RUN apt-get clean +#RUN apt-get update + +## .NET 8.0 默认使用8080端口,变更为80端口需要环境变量ASPNETCORE_HTTP_PORTS=80 +## .NET 8.0 defaults to port 8080, changing to port 80 requires the environment variable ASPNETCORE.HTTP-PORTS=80 +# EXPOSE 8080/tcp +EXPOSE 80/tcp + +VOLUME [ "./app/Logs" ] +VOLUME [ "./app/Modules" ] + +RUN apt update +RUN apt install wget -y + +ENTRYPOINT ["dotnet", "PackageName.CompanyName.ProjectName.HttpApi.Host.dll"] diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj new file mode 100644 index 000000000..81a3f0945 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/PackageName.CompanyName.ProjectName.HttpApi.Host.csproj @@ -0,0 +1,76 @@ + + + + net8.0 + PackageName.CompanyName.ProjectName + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Program.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Program.cs new file mode 100644 index 000000000..092cdeb82 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Program.cs @@ -0,0 +1,65 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Serilog; +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.IO; +using Volo.Abp.Modularity.PlugIns; + +namespace PackageName.CompanyName.ProjectName; + +public class Program +{ + public async static Task Main(string[] args) + { + try + { + Console.Title = "Web.Host"; + Log.Information("Starting web host."); + + var builder = WebApplication.CreateBuilder(args); + builder.Host.AddAppSettingsSecretsJson() + .UseAutofac() + .ConfigureAppConfiguration((context, config) => + { + var configuration = config.Build(); + var agileConfigEnabled = configuration["AgileConfig:IsEnabled"]; + if (agileConfigEnabled.IsNullOrEmpty() || bool.Parse(agileConfigEnabled)) + { + config.AddAgileConfig(new AgileConfig.Client.ConfigClient(configuration)); + } + }) + .UseSerilog((context, provider, config) => + { + config.ReadFrom.Configuration(context.Configuration); + }); + await builder.AddApplicationAsync(options => + { + ProjectNameHttpApiHostModule.ApplicationName = Environment.GetEnvironmentVariable("APPLICATION_NAME") + ?? ProjectNameHttpApiHostModule.ApplicationName; + options.ApplicationName = ProjectNameHttpApiHostModule.ApplicationName; + // 搜索 Modules 目录下所有文件作为插件 + // 取消显示引用所有其他项目的模块,改为通过插件的形式引用 + var pluginFolder = Path.Combine( + Directory.GetCurrentDirectory(), "Modules"); + DirectoryHelper.CreateIfNotExists(pluginFolder); + options.PlugInSources.AddFolder( + pluginFolder, + SearchOption.AllDirectories); + }); + var app = builder.Build(); + await app.InitializeApplicationAsync(); + await app.RunAsync(); + return 0; + } + finally + { + Log.CloseAndFlush(); + } + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.Configure.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.Configure.cs new file mode 100644 index 000000000..e7920d899 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.Configure.cs @@ -0,0 +1,445 @@ +using DotNetCore.CAP; +using LINGYUN.Abp.Dapr.Client.ClientProxying; +using LINGYUN.Abp.Dapr.Client.DynamicProxying; +using LINGYUN.Abp.ExceptionHandling; +using LINGYUN.Abp.ExceptionHandling.Emailing; +using LINGYUN.Abp.Localization.CultureMap; +using LINGYUN.Abp.Localization.Persistence; +using LINGYUN.Abp.Serilog.Enrichers.Application; +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; +using LINGYUN.Abp.Wrapper; +using Medallion.Threading; +using Medallion.Threading.Redis; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Caching.StackExchangeRedis; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; +using OpenTelemetry.Metrics; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; +using PackageName.CompanyName.ProjectName.Localization; +using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Encodings.Web; +using System.Text.Unicode; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.AntiForgery; +using Volo.Abp.Auditing; +using Volo.Abp.Caching; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.GlobalFeatures; +using Volo.Abp.Http.Client; +using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; +using Volo.Abp.Localization; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Security.Claims; +using Volo.Abp.Threading; +using Volo.Abp.VirtualFileSystem; +using static IdentityModel.ClaimComparer; + +namespace PackageName.CompanyName.ProjectName; + +public partial class ProjectNameHttpApiHostModule +{ + public static string ApplicationName { get; set; } = "ProjectNameService"; + private const string DefaultCorsPolicyName = "Default"; + private static readonly OneTimeRunner OneTimeRunner = new(); + + private void PreConfigureFeature() + { + OneTimeRunner.Run(() => + { + GlobalFeatureManager.Instance.Modules.Editions().EnableAll(); + }); + } + + private void PreConfigureApp() + { + AbpSerilogEnrichersConsts.ApplicationName = ApplicationName; + + PreConfigure(options => + { + // 以开放端口区别 + options.SnowflakeIdOptions.WorkerId = 5; + options.SnowflakeIdOptions.WorkerIdBits = 5; + options.SnowflakeIdOptions.DatacenterId = 1; + }); + } + + private void PreConfigureCAP(IConfiguration configuration) + { + PreConfigure(options => + { + options +#if MySQL + .UseMySql(sqlOptions => + { + configuration.GetSection("CAP:MySql").Bind(sqlOptions); + }) +#elif SqlServer + .UseSqlServer(sqlOptions => + { + configuration.GetSection("CAP:SqlServer").Bind(sqlOptions); + }) +#elif Sqlite + .UseSqlite(sqlOptions => + { + configuration.GetSection("CAP:Sqlite").Bind(sqlOptions); + }) +#elif Oracle || OracleDevart + .UseOracle(sqlOptions => + { + configuration.GetSection("CAP:Oracle").Bind(sqlOptions); + }) +#elif PostgreSql + .UsePostgreSql(sqlOptions => + { + configuration.GetSection("CAP:PostgreSql").Bind(sqlOptions); + }) +#endif + .UseRabbitMQ(rabbitMQOptions => + { + configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); + }) + .UseDashboard(); + }); + } + + private void ConfigureJsonSerializer(IConfiguration configuration) + { + // 统一时间日期格式 + Configure(options => + { + var jsonConfiguration = configuration.GetSection("Json"); + if (jsonConfiguration.Exists()) + { + jsonConfiguration.Bind(options); + } + }); + // 中文序列化的编码问题 + Configure(options => + { + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); + }); + } + + private void ConfigureDistributedLock(IServiceCollection services, IConfiguration configuration) + { + var distributedLockIsEnabled = configuration["DistributedLock:IsEnabled"]; + if (distributedLockIsEnabled.IsNullOrWhiteSpace() || bool.Parse(distributedLockIsEnabled)) + { + var redis = ConnectionMultiplexer.Connect(configuration["DistributedLock:Redis:Configuration"]); + services.AddSingleton(_ => new RedisDistributedSynchronizationProvider(redis.GetDatabase())); + } + } + + private void ConfigureOpenTelemetry(IServiceCollection services, IConfiguration configuration) + { + var openTelemetryEnabled = configuration["OpenTelemetry:IsEnabled"]; + if (openTelemetryEnabled.IsNullOrEmpty() || bool.Parse(openTelemetryEnabled)) + { + services.AddOpenTelemetry() + .ConfigureResource(resource => + { + resource.AddService(ApplicationName); + }) + .WithTracing(tracing => + { + tracing.AddHttpClientInstrumentation(); + tracing.AddAspNetCoreInstrumentation(); + tracing.AddCapInstrumentation(); + tracing.AddEntityFrameworkCoreInstrumentation(); + tracing.AddSource(ApplicationName); + + var tracingOtlpEndpoint = configuration["OpenTelemetry:Otlp:Endpoint"]; + if (!tracingOtlpEndpoint.IsNullOrWhiteSpace()) + { + tracing.AddOtlpExporter(otlpOptions => + { + otlpOptions.Endpoint = new Uri(tracingOtlpEndpoint); + }); + return; + } + + var zipkinEndpoint = configuration["OpenTelemetry:ZipKin:Endpoint"]; + if (!zipkinEndpoint.IsNullOrWhiteSpace()) + { + tracing.AddZipkinExporter(zipKinOptions => + { + zipKinOptions.Endpoint = new Uri(zipkinEndpoint); + }); + return; + } + }) + .WithMetrics(metrics => + { + metrics.AddRuntimeInstrumentation(); + metrics.AddHttpClientInstrumentation(); + metrics.AddAspNetCoreInstrumentation(); + }); + } + } + + private void ConfigureExceptionHandling() + { + // 自定义需要处理的异常 + Configure(options => + { + // 加入需要处理的异常类型 + options.Handlers.Add(); + options.Handlers.Add(); + options.Handlers.Add(); + options.Handlers.Add(); + options.Handlers.Add(); + options.Handlers.Add(); + }); + // 自定义需要发送邮件通知的异常类型 + Configure(options => + { + // 是否发送堆栈信息 + options.SendStackTrace = true; + // 未指定异常接收者的默认接收邮件 + // 指定自己的邮件地址 + }); + } + + private void ConfigureIdentity(IConfiguration configuration) + { + Configure(options => + { + options.IsDynamicClaimsEnabled = true; + var refreshClaimsUrl = configuration["App:RefreshClaimsUrl"]; + if (!refreshClaimsUrl.IsNullOrWhiteSpace()) + { + options.RemoteRefreshUrl = refreshClaimsUrl + options.RemoteRefreshUrl; + } + }); + } + + private void ConfigureAuditing(IConfiguration configuration) + { + Configure(options => + { + options.ApplicationName = ApplicationName; + // 是否启用实体变更记录 + var allEntitiesSelectorIsEnabled = configuration["Auditing:AllEntitiesSelector"]; + if (allEntitiesSelectorIsEnabled.IsNullOrWhiteSpace() || bool.Parse(allEntitiesSelectorIsEnabled)) + { + options.EntityHistorySelectors.AddAllEntities(); + } + }); + } + + private void ConfigureCaching(IConfiguration configuration) + { + Configure(options => + { + configuration.GetSection("DistributedCache").Bind(options); + }); + + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + } + + private void ConfigureMvc(IServiceCollection services, IConfiguration configuration) + { + Configure(options => + { + options.ExposeIntegrationServices = true; + }); + + Configure(options => + { + options.EndpointConfigureActions.Add((builder) => + { + builder.Endpoints.MapHealthChecks(configuration["App:HealthChecks"] ?? "/healthz"); + }); + }); + + services.AddHealthChecks(); + } + + private void ConfigureVirtualFileSystem() + { + Configure(options => + { + options.FileSets.AddEmbedded("PackageName.CompanyName.ProjectName"); + }); + } + + private void ConfigureMultiTenancy(IConfiguration configuration) + { + // 多租户 + Configure(options => + { + options.IsEnabled = true; + }); + + var tenantResolveCfg = configuration.GetSection("App:Domains"); + if (tenantResolveCfg.Exists()) + { + Configure(options => + { + var domains = tenantResolveCfg.Get(); + foreach (var domain in domains) + { + options.AddDomainTenantResolver(domain); + } + }); + } + } + + private void ConfigureSwagger(IServiceCollection services) + { + // Swagger + services.AddSwaggerGen( + options => + { + options.SwaggerDoc("v1", new OpenApiInfo { Title = "ProjectName API", Version = "v1" }); + options.DocInclusionPredicate((docName, description) => true); + options.CustomSchemaIds(type => type.FullName); + options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", + Name = "Authorization", + In = ParameterLocation.Header, + Scheme = "bearer", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT" + }); + options.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } + }, + new string[] { } + } + }); + options.OperationFilter(); + }); + } + + private void ConfigureLocalization() + { + // 支持本地化语言类型 + Configure(options => + { + options.Languages.Add(new LanguageInfo("en", "en", "English")); + options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); + }); + + Configure(options => + { + // 持久化本地化资源 + options.SaveStaticLocalizationsToPersistence = true; + options.AddPersistenceResource(); + }); + + Configure(options => + { + var zhHansCultureMapInfo = new CultureMapInfo + { + TargetCulture = "zh-Hans", + SourceCultures = new string[] { "zh", "zh_CN", "zh-CN" } + }; + + options.CulturesMaps.Add(zhHansCultureMapInfo); + options.UiCulturesMaps.Add(zhHansCultureMapInfo); + }); + } + + private void ConfigureSecurity(IServiceCollection services, IConfiguration configuration, bool isDevelopment = false) + { + Configure(options => + { + // options.AutoValidate = false; + // options.AutoValidateFilter = (type) => !type.Namespace.Contains("elsa", StringComparison.CurrentCultureIgnoreCase); + }); + + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + configuration.GetSection("AuthServer").Bind(options); + }); + + if (!isDevelopment) + { + var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + services + .AddDataProtection() + .SetApplicationName("LINGYUN.Abp.Application") + .PersistKeysToStackExchangeRedis(redis, "LINGYUN.Abp.Application:DataProtection:Protection-Keys"); + } + } + + private void ConfigureCors(IServiceCollection services, IConfiguration configuration) + { + services.AddCors(options => + { + options.AddPolicy(DefaultCorsPolicyName, builder => + { + builder + .WithOrigins( + configuration["App:CorsOrigins"] + .Split(",", StringSplitOptions.RemoveEmptyEntries) + .Select(o => o.RemovePostFix("/")) + .ToArray() + ) + .WithAbpExposedHeaders() + .WithAbpWrapExposedHeaders() + .SetIsOriginAllowedToAllowWildcardSubdomains() + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); + }); + } + + private void ConfigureWrapper() + { + Configure(options => + { + // 取消注释包装结果 + options.IsEnabled = true; + }); + } + + private void PreConfigureWrapper() + { + PreConfigure(options => + { + // http服务间调用发送不需要包装结果的请求头 + options.ProxyClientActions.Add( + (_, _, client) => + { + client.DefaultRequestHeaders.TryAddWithoutValidation(AbpHttpWrapConsts.AbpDontWrapResult, "true"); + }); + }); + + PreConfigure(options => + { + // dapr服务间调用发送不需要包装结果的请求头 + options.ProxyRequestActions.Add( + (appId, httpRequestMessage) => + { + httpRequestMessage.Headers.TryAddWithoutValidation(AbpHttpWrapConsts.AbpDontWrapResult, "true"); + }); + }); + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs new file mode 100644 index 000000000..28d5a1480 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/ProjectNameHttpApiHostModule.cs @@ -0,0 +1,127 @@ +using LINGYUN.Abp.AspNetCore.Mvc.Wrapper; +using LINGYUN.Abp.AuditLogging.Elasticsearch; +using LINGYUN.Abp.EventBus.CAP; +using LINGYUN.Abp.ExceptionHandling.Emailing; +using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; +using LINGYUN.Abp.TextTemplating.EntityFrameworkCore; +using LINGYUN.Abp.Saas.EntityFrameworkCore; +using LINGYUN.Abp.Serilog.Enrichers.Application; +using LINGYUN.Abp.Serilog.Enrichers.UniqueId; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using PackageName.CompanyName.ProjectName.EntityFrameworkCore; +using PackageName.CompanyName.ProjectName.SettingManagement; +using Volo.Abp; +using Volo.Abp.AspNetCore.Authentication.JwtBearer; +using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.AspNetCore.Serilog; +using Volo.Abp.Autofac; +using Volo.Abp.Caching.StackExchangeRedis; +using Volo.Abp.DistributedLocking; +using Volo.Abp.FeatureManagement.EntityFrameworkCore; +using Volo.Abp.Http.Client.IdentityModel.Web; +using Volo.Abp.Modularity; +using Volo.Abp.PermissionManagement.EntityFrameworkCore; +using Volo.Abp.SettingManagement.EntityFrameworkCore; +using Volo.Abp.Swashbuckle; +using LINGYUN.Abp.AspNetCore.HttpOverrides; +using LINGYUN.Abp.Identity.Session.AspNetCore; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpSerilogEnrichersApplicationModule), + typeof(AbpSerilogEnrichersUniqueIdModule), + typeof(AbpAuditLoggingElasticsearchModule), + typeof(AbpAspNetCoreSerilogModule), + typeof(ProjectNameApplicationModule), + typeof(ProjectNameHttpApiModule), + typeof(ProjectNameEntityFrameworkCoreModule), + typeof(ProjectNameSettingManagementModule), + typeof(AbpEmailingExceptionHandlingModule), + typeof(AbpCAPEventBusModule), + typeof(AbpHttpClientIdentityModelWebModule), + typeof(AbpAspNetCoreMultiTenancyModule), + typeof(AbpSaasEntityFrameworkCoreModule), + typeof(AbpFeatureManagementEntityFrameworkCoreModule), + typeof(AbpPermissionManagementEntityFrameworkCoreModule), + typeof(AbpSettingManagementEntityFrameworkCoreModule), + typeof(AbpLocalizationManagementEntityFrameworkCoreModule), + typeof(AbpTextTemplatingEntityFrameworkCoreModule), + typeof(AbpAspNetCoreAuthenticationJwtBearerModule), + typeof(AbpCachingStackExchangeRedisModule), + typeof(AbpDistributedLockingModule), + typeof(AbpAspNetCoreMvcWrapperModule), + typeof(AbpAspNetCoreHttpOverridesModule), + typeof(AbpIdentitySessionAspNetCoreModule), + typeof(AbpSwashbuckleModule), + typeof(AbpAutofacModule) + )] +public partial class ProjectNameHttpApiHostModule : AbpModule +{ + public override void PreConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + PreConfigureApp(); + PreConfigureWrapper(); + PreConfigureFeature(); + PreConfigureCAP(configuration); + } + + public override void ConfigureServices(ServiceConfigurationContext context) + { + var hostingEnvironment = context.Services.GetHostingEnvironment(); + var configuration = context.Services.GetConfiguration(); + + ConfigureWrapper(); + ConfigureLocalization(); + ConfigureExceptionHandling(); + ConfigureVirtualFileSystem(); + ConfigureCaching(configuration); + ConfigureAuditing(configuration); + ConfigureIdentity(configuration); + ConfigureMultiTenancy(configuration); + ConfigureJsonSerializer(configuration); + ConfigureSwagger(context.Services); + ConfigureMvc(context.Services, configuration); + ConfigureCors(context.Services, configuration); + ConfigureOpenTelemetry(context.Services, configuration); + ConfigureDistributedLock(context.Services, configuration); + ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var app = context.GetApplicationBuilder(); + var env = context.GetEnvironment(); + + app.UseForwardedHeaders(); + app.UseMapRequestLocalization(); + app.UseCorrelationId(); + app.UseStaticFiles(); + app.UseRouting(); + app.UseCors(); + app.UseAuthentication(); + app.UseJwtTokenMiddleware(); + app.UseMultiTenancy(); + app.UseAbpSession(); + app.UseDynamicClaims(); + app.UseAuthorization(); + app.UseSwagger(); + app.UseAbpSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support ProjectName API"); + + var configuration = context.GetConfiguration(); + options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); + options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); + options.OAuthScopes("ProjectName"); + }); + app.UseAuditing(); + app.UseAbpSerilogEnrichers(); + app.UseConfiguredEndpoints(); + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Properties/launchSettings.json b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Properties/launchSettings.json new file mode 100644 index 000000000..0d9c46f45 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:20890", + "sslPort": 0 + } + }, + "profiles": { + "PackageName.CompanyName.ProjectName.HttpApi.Host": { + "commandName": "Project", + "launchBrowser": false, + "dotnetRunMessages": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://127.0.0.1:5000" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/TenantHeaderParamter.cs b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/TenantHeaderParamter.cs new file mode 100644 index 000000000..e628695db --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/TenantHeaderParamter.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; +using System.Collections.Generic; +using Volo.Abp.MultiTenancy; + +namespace PackageName.CompanyName.ProjectName; + +public class TenantHeaderParamter : IOperationFilter +{ + private readonly AbpMultiTenancyOptions _options; + public TenantHeaderParamter( + IOptions options) + { + _options = options.Value; + } + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if (_options.IsEnabled) + { + operation.Parameters = operation.Parameters ?? new List(); + operation.Parameters.Add(new OpenApiParameter + { + Name = TenantResolverConsts.DefaultTenantKey, + In = ParameterLocation.Header, + Description = "Tenant Id/Name", + Required = false + }); + } + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json new file mode 100644 index 000000000..9f72f9390 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.Development.json @@ -0,0 +1,153 @@ +{ + "AgileConfig": { + "IsEnabled": false, + "env": "DEV", + "appId": "PackageName.CompanyName.ProjectName", + "secret": "1q2w3E*", + "nodes": "http://127.0.0.1:15000", + "name": "PackageName.CompanyName.ProjectName", + "tag": "PackageName.CompanyName.ProjectName" + }, + "App": { + "CorsOrigins": "http://127.0.0.1:30000", + "RefreshClaimsUrl": "http://127.0.0.1:30015/", + "HealthChecks": "/healthz" + }, + "Auditing": { + "AllEntitiesSelector": true + }, + "DistributedCache": { + "HideErrors": true, + "KeyPrefix": "LINGYUN.Abp.Application", + "GlobalCacheEntryOptions": { + "SlidingExpiration": "30:00:00", + "AbsoluteExpirationRelativeToNow": "60:00:00" + } + }, + "ConnectionStrings": { + "Default": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "ProjectName": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpSaas": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpFeatureManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpPermissionManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpSettingManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpLocalizationManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", + "AbpTextTemplating": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "DistributedLock": { + "IsEnabled": true, + "Redis": { + "Configuration": "127.0.0.1,defaultDatabase=15" + } + }, + "OpenTelemetry": { + "IsEnabled": true, + "ZipKin": { + "Endpoint": "http://127.0.0.1:9411/api/v2/spans" + } + }, + "RemoteServices": {}, + "IdentityClients": { + "InternalServiceClient": { + "Authority": "http://127.0.0.1:44385", + "RequireHttps": false, + "MapInboundClaims": false, + "GrantType": "client_credentials", + "Scope": "lingyun-abp-application", + "ClientId": "InternalServiceClient", + "ClientSecret": "1q2w3E*" + } + }, + "CAP": { + "EventBus": { + "DefaultGroupName": "ProjectName", + "GroupNamePrefix": "Dev", + "Version": "v1", + "FailedRetryInterval": 300, + "FailedRetryCount": 10 + }, + "MySql": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "SqlServer": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" + }, + "Sqlite": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Data Source=./cap.db" + }, + "Oracle": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Data Source=ProjectName;Integrated Security=yes;" + }, + "PostgreSql": { + "TableNamePrefix": "ProjectName_cap", + "ConnectionString": "Host=localhost;Port=5432;Database=ProjectName;User ID=root;Password=123456;" + }, + "RabbitMQ": { + "HostName": "127.0.0.1", + "Port": 5672, + "UserName": "admin", + "Password": "123456", + "ExchangeName": "LINGYUN.Abp.Application", + "VirtualHost": "/" + } + }, + "Redis": { + "Configuration": "127.0.0.1,defaultDatabase=10", + "InstanceName": "LINGYUN.Abp.Application" + }, + "AuthServer": { + "Authority": "http://127.0.0.1:44385/", + "Audience": "lingyun-abp-application", + "MapInboundClaims": false, + "RequireHttpsMetadata": false, + "SwaggerClientId": "InternalServiceClient", + "SwaggerClientSecret": "1q2w3E*" + }, + "Logging": { + "Serilog": { + "Elasticsearch": { + "IndexFormat": "abp.dev.logging-{0:yyyy.MM.dd}" + } + } + }, + "AuditLogging": { + "Elasticsearch": { + "IndexPrefix": "abp.dev.auditing" + } + }, + "Elasticsearch": { + "NodeUris": "http://127.0.0.1:9200" + }, + "Serilog": { + "MinimumLevel": { + "Default": "Debug", + "Override": { + "System": "Warning", + "Microsoft": "Warning", + "DotNetCore": "Debug" + } + }, + "WriteTo": [ + { + "Name": "Console", + "Args": { + "restrictedToMinimumLevel": "Debug", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "Elasticsearch", + "Args": { + "nodeUris": "http://127.0.0.1:9200", + "indexFormat": "abp.dev.logging-{0:yyyy.MM.dd}", + "autoRegisterTemplate": true, + "autoRegisterTemplateVersion": "ESv7" + } + } + ] + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.json b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.json new file mode 100644 index 000000000..b9c69ab64 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/appsettings.json @@ -0,0 +1,88 @@ +{ + "Clock": { + "Kind": "Local" + }, + "Forwarded": { + "ForwardedHeaders": "XForwardedFor,XForwardedProto" + }, + "StringEncryption": { + "DefaultPassPhrase": "s46c5q55nxpeS8Ra", + "InitVectorBytes": "s83ng0abvd02js84", + "DefaultSalt": "sf&5)s3#" + }, + "Json": { + "OutputDateTimeFormat": "yyyy-MM-dd HH:mm:ss", + "InputDateTimeFormats": [ + "yyyy-MM-dd HH:mm:ss", + "yyyy-MM-ddTHH:mm:ss" + ] + }, + "AllowedHosts": "*", + "Serilog": { + "MinimumLevel": { + "Default": "Debug", + "Override": { + "Microsoft.EntityFrameworkCore": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName", "WithUniqueId" ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "initialMinimumLevel": "Verbose", + "standardErrorFromLevel": "Verbose", + "restrictedToMinimumLevel": "Verbose", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Debug-.log", + "restrictedToMinimumLevel": "Debug", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Info-.log", + "restrictedToMinimumLevel": "Information", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Warn-.log", + "restrictedToMinimumLevel": "Warning", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Error-.log", + "restrictedToMinimumLevel": "Error", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "Logs/Fatal-.log", + "restrictedToMinimumLevel": "Fatal", + "rollingInterval": "Day", + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" + } + } + ] + } +} diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/dapr.sh b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/dapr.sh new file mode 100644 index 000000000..01a8eb036 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/dapr.sh @@ -0,0 +1 @@ +dapr run --app-id ProjectName --app-port 5000 -H 3500 -- dotnet run --no-build \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/generate-proxy.sh b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/generate-proxy.sh new file mode 100644 index 000000000..45013ae98 --- /dev/null +++ b/aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.HttpApi.Host/generate-proxy.sh @@ -0,0 +1,2 @@ +cd ../src/PackageName.CompanyName.ProjectName.HttpApi.Client +abp generate-proxy -t csharp -m ProjectName -url http://127.0.0.1:5000/ --without-contracts \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName.CompanyName.ProjectName.Application.Contracts.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName.CompanyName.ProjectName.Application.Contracts.csproj new file mode 100644 index 000000000..0eaa24015 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName.CompanyName.ProjectName.Application.Contracts.csproj @@ -0,0 +1,27 @@ + + + + + + + netstandard2.0;netstandard2.1;net8.0 + PackageName.CompanyName.ProjectName.Application.Contracts + PackageName.CompanyName.ProjectName.Application.Contracts + false + false + false + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs new file mode 100644 index 000000000..5fed2b916 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs @@ -0,0 +1,18 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Volo.Abp.Features; +using Volo.Abp.Localization; + +namespace PackageName.CompanyName.ProjectName.Features; + +public class ProjectNameFeatureDefinitionProvider : FeatureDefinitionProvider +{ + public override void Define(IFeatureDefinitionContext context) + { + var group = context.AddGroup(ProjectNameFeatureNames.GroupName, L("Features:ProjectName")); + } + + private static ILocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs new file mode 100644 index 000000000..6389fbcf6 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs @@ -0,0 +1,6 @@ +namespace PackageName.CompanyName.ProjectName.Features; + +public static class ProjectNameFeatureNames +{ + public const string GroupName = "ProjectName"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/IProjectNameDynamicQueryableAppService.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/IProjectNameDynamicQueryableAppService.cs new file mode 100644 index 000000000..6f132d9a3 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/IProjectNameDynamicQueryableAppService.cs @@ -0,0 +1,10 @@ +using LINGYUN.Abp.Dynamic.Queryable; + +namespace PackageName.CompanyName.ProjectName; +/// +/// 提供动态查询接口定义 +/// +/// 实体dto类型 +public interface IProjectNameDynamicQueryableAppService : IDynamicQueryableAppService +{ +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissionDefinitionProvider.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissionDefinitionProvider.cs new file mode 100644 index 000000000..4a170551b --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissionDefinitionProvider.cs @@ -0,0 +1,22 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Localization; + +namespace PackageName.CompanyName.ProjectName.Permissions; + +public class ProjectNamePermissionDefinitionProvider : PermissionDefinitionProvider +{ + public override void Define(IPermissionDefinitionContext context) + { + var group = context.AddGroup(ProjectNamePermissions.GroupName, L("Permission:ProjectName")); + + group.AddPermission( + ProjectNamePermissions.ManageSettings, + L("Permission:ManageSettings")); + } + + private static LocalizableString L(string name) + { + return LocalizableString.Create(name); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissions.cs new file mode 100644 index 000000000..98a957ff9 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/Permissions/ProjectNamePermissions.cs @@ -0,0 +1,8 @@ +namespace PackageName.CompanyName.ProjectName.Permissions; + +public static class ProjectNamePermissions +{ + public const string GroupName = "ProjectName"; + + public const string ManageSettings = GroupName + ".ManageSettings"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameApplicationContractsModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameApplicationContractsModule.cs new file mode 100644 index 000000000..eb0b2fb15 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameApplicationContractsModule.cs @@ -0,0 +1,17 @@ +using LINGYUN.Abp.Dynamic.Queryable; +using Volo.Abp.Application; +using Volo.Abp.Authorization; +using Volo.Abp.Features; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpFeaturesModule), + typeof(AbpAuthorizationModule), + typeof(AbpDddApplicationContractsModule), + typeof(AbpDynamicQueryableApplicationContractsModule), + typeof(ProjectNameDomainSharedModule))] +public class ProjectNameApplicationContractsModule : AbpModule +{ +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameRemoteServiceConsts.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameRemoteServiceConsts.cs new file mode 100644 index 000000000..4b5bb260d --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application.Contracts/PackageName/CompanyName/ProjectName/ProjectNameRemoteServiceConsts.cs @@ -0,0 +1,7 @@ +namespace PackageName.CompanyName.ProjectName; + +public static class ProjectNameRemoteServiceConsts +{ + public const string RemoteServiceName = "ProjectName"; + public const string ModuleName = "ProjectName"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName.CompanyName.ProjectName.Application.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName.CompanyName.ProjectName.Application.csproj new file mode 100644 index 000000000..cf195e665 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName.CompanyName.ProjectName.Application.csproj @@ -0,0 +1,26 @@ + + + + + + + net8.0 + PackageName.CompanyName.ProjectName.Application + PackageName.CompanyName.ProjectName.Application + false + false + false + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameAppServiceBase.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameAppServiceBase.cs new file mode 100644 index 000000000..496140dfe --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameAppServiceBase.cs @@ -0,0 +1,13 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Volo.Abp.Application.Services; + +namespace PackageName.CompanyName.ProjectName; + +public abstract class ProjectNameAppServiceBase : ApplicationService +{ + protected ProjectNameAppServiceBase() + { + LocalizationResource = typeof(ProjectNameResource); + ObjectMapperContext = typeof(ProjectNameApplicationModule); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationMapperProfile.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationMapperProfile.cs new file mode 100644 index 000000000..0ace9b456 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationMapperProfile.cs @@ -0,0 +1,10 @@ +using AutoMapper; + +namespace PackageName.CompanyName.ProjectName; + +public class ProjectNameApplicationMapperProfile : Profile +{ + public ProjectNameApplicationMapperProfile() + { + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationModule.cs new file mode 100644 index 000000000..6e1cf009f --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameApplicationModule.cs @@ -0,0 +1,27 @@ +using LINGYUN.Abp.Dynamic.Queryable; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Application; +using Volo.Abp.Authorization; +using Volo.Abp.AutoMapper; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpAuthorizationModule), + typeof(AbpDddApplicationModule), + typeof(ProjectNameDomainModule), + typeof(ProjectNameApplicationContractsModule), + typeof(AbpDynamicQueryableApplicationModule))] +public class ProjectNameApplicationModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAutoMapperObjectMapper(); + + Configure(options => + { + options.AddProfile(validate: true); + }); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableAppServiceBase.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableAppServiceBase.cs new file mode 100644 index 000000000..e20348b53 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableAppServiceBase.cs @@ -0,0 +1,19 @@ +using LINGYUN.Abp.Dynamic.Queryable; +using PackageName.CompanyName.ProjectName.Localization; + +namespace PackageName.CompanyName.ProjectName; +/// +/// 提供动态查询接口实现 +/// +/// 实体类型 +/// 实体dto类型 +public abstract class ProjectNameDynamicQueryableAppServiceBase : + DynamicQueryableAppService, + IProjectNameDynamicQueryableAppService +{ + protected ProjectNameDynamicQueryableAppServiceBase() + { + LocalizationResource = typeof(ProjectNameResource); + ObjectMapperContext = typeof(ProjectNameApplicationModule); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/System/Linq/Expressions/ExpressionFuncExtensions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/System/Linq/Expressions/ExpressionFuncExtensions.cs new file mode 100644 index 000000000..fd7a017ea --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Application/System/Linq/Expressions/ExpressionFuncExtensions.cs @@ -0,0 +1,32 @@ +using Volo.Abp.Specifications; + +namespace System.Linq.Expressions; + +internal static class ExpressionFuncExtensions +{ + public static Expression> AndIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.And(first, second); + } + + return first; + } + + public static Expression> OrIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.Or(first, second); + } + + return first; + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName.CompanyName.ProjectName.Dapr.Client.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName.CompanyName.ProjectName.Dapr.Client.csproj new file mode 100644 index 000000000..aa6f4772b --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName.CompanyName.ProjectName.Dapr.Client.csproj @@ -0,0 +1,19 @@ + + + + + + + net8.0 + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName/CompanyName/ProjectName/ProjectNameDaprClientModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName/CompanyName/ProjectName/ProjectNameDaprClientModule.cs new file mode 100644 index 000000000..ca16b0bf1 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Dapr.Client/PackageName/CompanyName/ProjectName/ProjectNameDaprClientModule.cs @@ -0,0 +1,18 @@ +using LINGYUN.Abp.Dapr.Client; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpDaprClientModule), + typeof(ProjectNameApplicationContractsModule))] +public class ProjectNameDaprClientModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddStaticDaprClientProxies( + typeof(ProjectNameApplicationContractsModule).Assembly, + ProjectNameRemoteServiceConsts.RemoteServiceName); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName.CompanyName.ProjectName.Domain.Shared.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName.CompanyName.ProjectName.Domain.Shared.csproj new file mode 100644 index 000000000..cd98bbcf9 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName.CompanyName.ProjectName.Domain.Shared.csproj @@ -0,0 +1,30 @@ + + + + + + + netstandard2.0;netstandard2.1;net8.0 + PackageName.CompanyName.ProjectName.Domain.Shared + PackageName.CompanyName.ProjectName.Domain.Shared + false + false + false + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/ProjectNameResource.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/ProjectNameResource.cs new file mode 100644 index 000000000..b0c280d5a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/ProjectNameResource.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Localization; + +namespace PackageName.CompanyName.ProjectName.Localization; + +[LocalizationResourceName("ProjectName")] +public class ProjectNameResource +{ +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/en.json b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/en.json new file mode 100644 index 000000000..d14e6f1dd --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/en.json @@ -0,0 +1,8 @@ +{ + "culture": "en", + "texts": { + "Features:ProjectName": "ProjectName", + "Permission:ProjectName": "ProjectName", + "Permission:ManageSettings": "Manage Settings" + } +} \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/zh-Hans.json b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/zh-Hans.json new file mode 100644 index 000000000..c85b3754a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Localization/Resources/zh-Hans.json @@ -0,0 +1,8 @@ +{ + "culture": "zh-Hans", + "texts": { + "Features:ProjectName": "ProjectName", + "Permission:ProjectName": "ProjectName", + "Permission:ManageSettings": "管理设置" + } +} \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfiguration.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfiguration.cs new file mode 100644 index 000000000..6634ceb15 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfiguration.cs @@ -0,0 +1,16 @@ +using System; +using Volo.Abp.ObjectExtending.Modularity; + +namespace PackageName.CompanyName.ProjectName.ObjectExtending; + +public class ProjectNameModuleExtensionConfiguration : ModuleExtensionConfiguration +{ + public ProjectNameModuleExtensionConfiguration ConfigureProjectName( + Action configureAction) + { + return this.ConfigureEntity( + ProjectNameModuleExtensionConsts.EntityNames.Entity, + configureAction + ); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfigurationDictionaryExtensions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfigurationDictionaryExtensions.cs new file mode 100644 index 000000000..fabfd40c9 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConfigurationDictionaryExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.ObjectExtending.Modularity; + +namespace PackageName.CompanyName.ProjectName.ObjectExtending; + +public static class ProjectNameModuleExtensionConfigurationDictionaryExtensions +{ + public static ModuleExtensionConfigurationDictionary ConfigureProjectName( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) + { + return modules.ConfigureModule( + ProjectNameModuleExtensionConsts.ModuleName, + configureAction + ); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConsts.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConsts.cs new file mode 100644 index 000000000..1973ef9b6 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ObjectExtending/ProjectNameModuleExtensionConsts.cs @@ -0,0 +1,11 @@ +namespace PackageName.CompanyName.ProjectName.ObjectExtending; + +public static class ProjectNameModuleExtensionConsts +{ + public const string ModuleName = "ProjectName"; + + public static class EntityNames + { + public const string Entity = "Entity"; + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameDomainSharedModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameDomainSharedModule.cs new file mode 100644 index 000000000..ec682b498 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameDomainSharedModule.cs @@ -0,0 +1,32 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Volo.Abp.Localization; +using Volo.Abp.Localization.ExceptionHandling; +using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpLocalizationModule))] +public class ProjectNameDomainSharedModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Add() + .AddVirtualJson("/PackageName/CompanyName/ProjectName/Localization/Resources"); + }); + + Configure(options => + { + options.MapCodeNamespace(ProjectNameErrorCodes.Namespace, typeof(ProjectNameResource)); + }); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameErrorCodes.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameErrorCodes.cs new file mode 100644 index 000000000..b2383ee40 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/ProjectNameErrorCodes.cs @@ -0,0 +1,6 @@ +namespace PackageName.CompanyName.ProjectName; + +public static class ProjectNameErrorCodes +{ + public const string Namespace = "ProjectName"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName.CompanyName.ProjectName.Domain.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName.CompanyName.ProjectName.Domain.csproj new file mode 100644 index 000000000..2cccd0944 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName.CompanyName.ProjectName.Domain.csproj @@ -0,0 +1,27 @@ + + + + + + + net8.0 + PackageName.CompanyName.ProjectName.Domain + PackageName.CompanyName.ProjectName.Domain + false + false + false + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/IProjectNameBasicRepository.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/IProjectNameBasicRepository.cs new file mode 100644 index 000000000..290e09398 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/IProjectNameBasicRepository.cs @@ -0,0 +1,54 @@ +using LINGYUN.Abp.DataProtection; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Specifications; + +namespace PackageName.CompanyName.ProjectName; +/// +/// 基本仓储接口 +/// +/// 实体类型 +/// 实体主键类型 +public interface IProjectNameBasicRepository : IDataProtectionRepository + where TEntity : class, IEntity +{ + /// + /// 获取过滤后的实体数量 + /// + /// + /// + /// + Task GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default); + /// + /// 获取过滤后的实体列表(分页) + /// + /// + /// + /// + /// + /// + /// + Task> GetListAsync( + ISpecification specification, + string sorting = nameof(IEntity.Id), + int maxResultCount = 10, + int skipCount = 0, + CancellationToken cancellationToken = default); + /// + /// 获取过滤后的实体列表 + /// + /// + /// + /// + /// + /// + Task> GetListAsync( + ISpecification specification, + string sorting = nameof(IEntity.Id), + int maxResultCount = 10, + CancellationToken cancellationToken = default); +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDbProperties.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDbProperties.cs new file mode 100644 index 000000000..a18947c6c --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDbProperties.cs @@ -0,0 +1,11 @@ +namespace PackageName.CompanyName.ProjectName; + +public static class ProjectNameDbProperties +{ + public static string DbTablePrefix { get; set; } = "ProjectName_"; + + public static string DbSchema { get; set; } = null; + + + public const string ConnectionStringName = "ProjectName"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainMapperProfile.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainMapperProfile.cs new file mode 100644 index 000000000..79c7af553 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainMapperProfile.cs @@ -0,0 +1,11 @@ +using AutoMapper; + +namespace PackageName.CompanyName.ProjectName; + +public class ProjectNameDomainMapperProfile : Profile +{ + public ProjectNameDomainMapperProfile() + { + + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainModule.cs new file mode 100644 index 000000000..401aa849e --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/ProjectNameDomainModule.cs @@ -0,0 +1,45 @@ +using LINGYUN.Abp.DataProtection; +using Microsoft.Extensions.DependencyInjection; +using PackageName.CompanyName.ProjectName.ObjectExtending; +using Volo.Abp.AutoMapper; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending.Modularity; +using Volo.Abp.Threading; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpAutoMapperModule), + typeof(AbpDataProtectionModule), + typeof(ProjectNameDomainSharedModule))] +public class ProjectNameDomainModule : AbpModule +{ + private static readonly OneTimeRunner OneTimeRunner = new(); + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAutoMapperObjectMapper(); + + Configure(options => + { + options.AddProfile(validate: true); + }); + + Configure(options => + { + }); + } + + public override void PostConfigureServices(ServiceConfigurationContext context) + { + OneTimeRunner.Run(() => + { + // 扩展实体配置 + //ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + // ProjectNameModuleExtensionConsts.ModuleName, + // ProjectNameModuleExtensionConsts.EntityNames.Entity, + // typeof(Entity) + //); + }); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettingDefinitionProvider.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettingDefinitionProvider.cs new file mode 100644 index 000000000..cdfdef118 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettingDefinitionProvider.cs @@ -0,0 +1,10 @@ +using Volo.Abp.Settings; + +namespace PackageName.CompanyName.ProjectName.Settings; + +public class ProjectNameSettingDefinitionProvider : SettingDefinitionProvider +{ + public override void Define(ISettingDefinitionContext context) + { + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettings.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettings.cs new file mode 100644 index 000000000..deb0b7b71 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Settings/ProjectNameSettings.cs @@ -0,0 +1,6 @@ +namespace PackageName.CompanyName.ProjectName.Settings; + +public static class ProjectNameSettings +{ + public const string GroupName = "ProjectName"; +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs new file mode 100644 index 000000000..fd7a017ea --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs @@ -0,0 +1,32 @@ +using Volo.Abp.Specifications; + +namespace System.Linq.Expressions; + +internal static class ExpressionFuncExtensions +{ + public static Expression> AndIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.And(first, second); + } + + return first; + } + + public static Expression> OrIf( + this Expression> first, + bool condition, + Expression> second) + { + if (condition) + { + return ExpressionFuncExtender.Or(first, second); + } + + return first; + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName.CompanyName.ProjectName.EntityFrameworkCore.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName.CompanyName.ProjectName.EntityFrameworkCore.csproj new file mode 100644 index 000000000..05ba83db3 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName.CompanyName.ProjectName.EntityFrameworkCore.csproj @@ -0,0 +1,37 @@ + + + + + + + net8.0 + PackageName.CompanyName.ProjectName.EntityFrameworkCore + PackageName.CompanyName.ProjectName.EntityFrameworkCore + false + false + false + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/EfCoreProjectNameRepository.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/EfCoreProjectNameRepository.cs new file mode 100644 index 000000000..2d68cf660 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/EfCoreProjectNameRepository.cs @@ -0,0 +1,77 @@ +using LINGYUN.Abp.DataProtection; +using LINGYUN.Abp.DataProtection.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Specifications; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; +/// +/// 实现基本接口 +/// +/// 实体类型 +/// 实体主键类型 +public abstract class EfCoreProjectNameRepository : + EfCoreDataProtectionRepository, + IProjectNameBasicRepository + where TEntity : class, IEntity +{ + protected EfCoreProjectNameRepository( + IDbContextProvider dbContextProvider, + IDataAuthorizationService dataAuthorizationService, + IEntityTypeFilterBuilder entityTypeFilterBuilder) + : base(dbContextProvider, dataAuthorizationService, entityTypeFilterBuilder) + { + } + + public async virtual Task GetCountAsync( + ISpecification specification, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(specification.ToExpression()) + .CountAsync(GetCancellationToken(cancellationToken)); + } + + public async virtual Task> GetListAsync( + ISpecification specification, + string sorting = nameof(IEntity.Id), + int maxResultCount = 10, + int skipCount = 0, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(specification.ToExpression()) + .OrderBy(GetSortingOrDefault(sorting)) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + public async virtual Task> GetListAsync( + ISpecification specification, + string sorting = nameof(IEntity.Id), + int maxResultCount = 10, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(specification.ToExpression()) + .OrderBy(GetSortingOrDefault(sorting)) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + protected virtual string GetSortingOrDefault(string sorting = nameof(IEntity.Id)) + { + if (sorting.IsNullOrWhiteSpace()) + { + return nameof(IEntity.Id); + } + return sorting; + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/IProjectNameDbContext.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/IProjectNameDbContext.cs new file mode 100644 index 000000000..c39c2923e --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/IProjectNameDbContext.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Data; +using Volo.Abp.EntityFrameworkCore; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +[ConnectionStringName(ProjectNameDbProperties.ConnectionStringName)] +public interface IProjectNameDbContext : IEfCoreDbContext +{ +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContext.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContext.cs new file mode 100644 index 000000000..5cb2c015b --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContext.cs @@ -0,0 +1,21 @@ +using LINGYUN.Abp.DataProtection.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Data; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +[ConnectionStringName(ProjectNameDbProperties.ConnectionStringName)] +public class ProjectNameDbContext : AbpDataProtectionDbContext, IProjectNameDbContext +{ + public ProjectNameDbContext( + DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.ConfigureProjectName(); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextFactory.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextFactory.cs new file mode 100644 index 000000000..d9ffcb9ca --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextFactory.cs @@ -0,0 +1,49 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; +using System.IO; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; +public class ProjectNameDbContextFactory : IDesignTimeDbContextFactory +{ + public ProjectNameDbContext CreateDbContext(string[] args) + { + var configuration = BuildConfiguration(); + var connectionString = configuration.GetConnectionString("ProjectName"); + + DbContextOptionsBuilder builder = null; + +#if MySQL + builder = new DbContextOptionsBuilder() + .UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); +#elif SqlServer + builder = new DbContextOptionsBuilder() + .UseSqlServer(connectionString); +#elif Sqlite + builder = new DbContextOptionsBuilder() + .UseSqlite(connectionString); +#elif Oracle + builder = new DbContextOptionsBuilder() + .UseOracle(connectionString); +#elif OracleDevart + builder = (DbContextOptionsBuilder) new DbContextOptionsBuilder() + .UseOracle(connectionString); +#elif PostgreSql + builder = new DbContextOptionsBuilder() + .UseNpgsql(connectionString); +#endif + + return new ProjectNameDbContext(builder!.Options); + } + + private static IConfigurationRoot BuildConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../PackageName.CompanyName.ProjectName.DbMigrator/")) + .AddJsonFile("appsettings.json", optional: false) + .AddJsonFile("appsettings.Development.json", optional: true); + + return builder.Build(); + } +} + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextModelCreatingExtensions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextModelCreatingExtensions.cs new file mode 100644 index 000000000..726b4ec9a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbContextModelCreatingExtensions.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System; +using Volo.Abp; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public static class ProjectNameDbContextModelCreatingExtensions +{ + public static void ConfigureProjectName( + this ModelBuilder builder, + Action optionsAction = null) + { + Check.NotNull(builder, nameof(builder)); + + var options = new ProjectNameModelBuilderConfigurationOptions( + ProjectNameDbProperties.DbTablePrefix, + ProjectNameDbProperties.DbSchema + ); + optionsAction?.Invoke(options); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs new file mode 100644 index 000000000..74a4a39bc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; +using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; +using Volo.Abp.EntityFrameworkCore.Migrations; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Uow; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public class ProjectNameDbMigrationEventHandler : EfCoreDatabaseMigrationEventHandlerBase +{ + protected IDataSeeder DataSeeder { get; } + + public ProjectNameDbMigrationEventHandler( + IDataSeeder dataSeeder, + ITenantStore tenantStore, + ICurrentTenant currentTenant, + IUnitOfWorkManager unitOfWorkManager, + IAbpDistributedLock abpDistributedLock, + IDistributedEventBus distributedEventBus, + ILoggerFactory loggerFactory) + : base( + ConnectionStringNameAttribute.GetConnStringName(), + currentTenant, unitOfWorkManager, tenantStore, abpDistributedLock, distributedEventBus, loggerFactory) + { + DataSeeder = dataSeeder; + } + + protected async override Task SeedAsync(Guid? tenantId) + { + await DataSeeder.SeedAsync(tenantId); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs new file mode 100644 index 000000000..70d5d69e8 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs @@ -0,0 +1,58 @@ +using LINGYUN.Abp.Data.DbMigrator; +using LINGYUN.Abp.Saas.Tenants; +using Microsoft.Extensions.Logging; +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.DistributedLocking; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Uow; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public class ProjectNameDbMigrationService : EfCoreRuntimeDbMigratorBase, ITransientDependency +{ + protected IDataSeeder DataSeeder { get; } + protected IDbSchemaMigrator DbSchemaMigrator { get; } + protected ITenantRepository TenantRepository { get; } + + public ProjectNameDbMigrationService( + IDataSeeder dataSeeder, + IDbSchemaMigrator dbSchemaMigrator, + ITenantRepository tenantRepository, + ICurrentTenant currentTenant, + IUnitOfWorkManager unitOfWorkManager, + IServiceProvider serviceProvider, + IAbpDistributedLock abpDistributedLock, + IDistributedEventBus distributedEventBus, + ILoggerFactory loggerFactory) + : base( + ConnectionStringNameAttribute.GetConnStringName(), + unitOfWorkManager, serviceProvider, currentTenant, abpDistributedLock, distributedEventBus, loggerFactory) + { + DataSeeder = dataSeeder; + DbSchemaMigrator = dbSchemaMigrator; + TenantRepository = tenantRepository; + } + + protected async override Task LockAndApplyDatabaseMigrationsAsync() + { + await base.LockAndApplyDatabaseMigrationsAsync(); + + var tenants = await TenantRepository.GetListAsync(); + foreach (var tenant in tenants.Where(x => x.IsActive)) + { + await LockAndApplyDatabaseWithTenantMigrationsAsync(tenant.Id); + } + } + + protected async override Task SeedAsync() + { + Logger.LogInformation($"Executing {(!CurrentTenant.IsAvailable ? "host" : CurrentTenant.Name ?? CurrentTenant.GetId().ToString())} database seed..."); + + await DataSeeder.SeedAsync(CurrentTenant.Id); + } +} \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEfCoreQueryableExtensions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEfCoreQueryableExtensions.cs new file mode 100644 index 000000000..90b369745 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEfCoreQueryableExtensions.cs @@ -0,0 +1,6 @@ +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public static class ProjectNameEfCoreQueryableExtensions +{ + // 在此聚合仓储服务的扩展方法 +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreModule.cs new file mode 100644 index 000000000..b18f43183 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreModule.cs @@ -0,0 +1,76 @@ +using LINGYUN.Abp.Data.DbMigrator; +using LINGYUN.Abp.DataProtection.EntityFrameworkCore; +using LINGYUN.Abp.Saas.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Modularity; +#if MySQL +using Volo.Abp.EntityFrameworkCore.MySQL; +#elif SqlServer +using Volo.Abp.EntityFrameworkCore.SqlServer; +using Microsoft.EntityFrameworkCore.Infrastructure; +#elif Sqlite +using Volo.Abp.EntityFrameworkCore.Sqlite; +#elif Oracle +using Volo.Abp.EntityFrameworkCore.Oracle; +#elif OracleDevart +using Volo.Abp.EntityFrameworkCore.Oracle.Devart; +#elif PostgreSql +using Volo.Abp.EntityFrameworkCore.PostgreSql; +#endif + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +[DependsOn( + typeof(ProjectNameDomainModule), + typeof(AbpDataDbMigratorModule), + typeof(AbpDataProtectionEntityFrameworkCoreModule), +#if MySQL + typeof(AbpEntityFrameworkCoreMySQLModule), +#elif SqlServer + typeof(AbpEntityFrameworkCoreSqlServerModule), +#elif Sqlite + typeof(AbpEntityFrameworkCoreSqliteModule), +#elif Oracle + typeof(AbpEntityFrameworkCoreOracleModule), +#elif OracleDevart + typeof(AbpEntityFrameworkCoreOracleDevartModule), +#elif PostgreSql + typeof(AbpEntityFrameworkCorePostgreSqlModule), +#endif + typeof(AbpSaasEntityFrameworkCoreModule))] +public class ProjectNameEntityFrameworkCoreModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + // 配置Ef + Configure(options => + { +#if MySQL + options.UseMySQL(); + options.UseMySQL(); +#elif SqlServer + options.UseSqlServer(); + options.UseSqlServer(builder => + { + // see https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level?view=sql-server-ver16 + // builder.UseCompatibilityLevel(150); + }); +#elif Sqlite + options.UseSqlite(); + options.UseSqlite(); +#elif Oracle || OracleDevart + options.UseOracle(); + options.UseOracle(); +#elif PostgreSql + options.UseNpgsql(); + options.UseNpgsql(); +#endif + }); + + context.Services.AddAbpDbContext(options => + { + options.AddDefaultRepositories(); + }); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameModelBuilderConfigurationOptions.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameModelBuilderConfigurationOptions.cs new file mode 100644 index 000000000..5849eb902 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameModelBuilderConfigurationOptions.cs @@ -0,0 +1,17 @@ +using JetBrains.Annotations; +using Volo.Abp.EntityFrameworkCore.Modeling; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public class ProjectNameModelBuilderConfigurationOptions : AbpModelBuilderConfigurationOptions +{ + public ProjectNameModelBuilderConfigurationOptions( + [NotNull] string tablePrefix = "", + [CanBeNull] string schema = null) + : base( + tablePrefix, + schema) + { + + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName.CompanyName.ProjectName.HttpApi.Client.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName.CompanyName.ProjectName.HttpApi.Client.csproj new file mode 100644 index 000000000..30cf00fd9 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName.CompanyName.ProjectName.HttpApi.Client.csproj @@ -0,0 +1,24 @@ + + + + + + + netstandard2.0;netstandard2.1;net8.0 + PackageName.CompanyName.ProjectName.HttpApi.Client + PackageName.CompanyName.ProjectName.HttpApi.Client + false + false + false + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName/CompanyName/ProjectName/ProjectNameHttpApiClientModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName/CompanyName/ProjectName/ProjectNameHttpApiClientModule.cs new file mode 100644 index 000000000..831ba468a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi.Client/PackageName/CompanyName/ProjectName/ProjectNameHttpApiClientModule.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Http.Client; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpHttpClientModule), + typeof(ProjectNameApplicationContractsModule))] +public class ProjectNameHttpApiClientModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddStaticHttpClientProxies( + typeof(ProjectNameApplicationContractsModule).Assembly, + ProjectNameRemoteServiceConsts.RemoteServiceName); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName.CompanyName.ProjectName.HttpApi.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName.CompanyName.ProjectName.HttpApi.csproj new file mode 100644 index 000000000..0f2375f61 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName.CompanyName.ProjectName.HttpApi.csproj @@ -0,0 +1,25 @@ + + + + + + + net8.0 + PackageName.CompanyName.ProjectName.HttpApi + PackageName.CompanyName.ProjectName.HttpApi + false + false + false + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameControllerBase.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameControllerBase.cs new file mode 100644 index 000000000..7345f99ea --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameControllerBase.cs @@ -0,0 +1,12 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Volo.Abp.AspNetCore.Mvc; + +namespace PackageName.CompanyName.ProjectName; + +public abstract class ProjectNameControllerBase : AbpControllerBase +{ + protected ProjectNameControllerBase() + { + LocalizationResource = typeof(ProjectNameResource); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableControllerBase.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableControllerBase.cs new file mode 100644 index 000000000..41cfe834a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameDynamicQueryableControllerBase.cs @@ -0,0 +1,17 @@ +using LINGYUN.Abp.Dynamic.Queryable; +using PackageName.CompanyName.ProjectName.Localization; + +namespace PackageName.CompanyName.ProjectName; +/// +/// 提供动态查询控制器实现 +/// +/// 实体dto类型 +public abstract class ProjectNameDynamicQueryableControllerBase : DynamicQueryableControllerBase +{ + protected ProjectNameDynamicQueryableControllerBase( + IDynamicQueryableAppService service) + : base(service) + { + LocalizationResource = typeof(ProjectNameResource); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameHttpApiModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameHttpApiModule.cs new file mode 100644 index 000000000..3a68e60da --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.HttpApi/PackageName/CompanyName/ProjectName/ProjectNameHttpApiModule.cs @@ -0,0 +1,42 @@ +using PackageName.CompanyName.ProjectName.Localization; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.Localization; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; +using Volo.Abp.Validation.Localization; +using LINGYUN.Abp.Dynamic.Queryable; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpAspNetCoreMvcModule), + typeof(ProjectNameApplicationContractsModule), + typeof(AbpDynamicQueryableHttpApiModule))] +public class ProjectNameHttpApiModule : AbpModule +{ + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(mvcBuilder => + { + mvcBuilder.AddApplicationPartIfNotExists(typeof(ProjectNameHttpApiModule).Assembly); + }); + + PreConfigure(options => + { + options.AddAssemblyResource( + typeof(ProjectNameResource), + typeof(ProjectNameApplicationContractsModule).Assembly); + }); + } + + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.Resources + .Get() + .AddBaseTypes(typeof(AbpValidationResource)); + }); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xml b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xsd b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName.CompanyName.ProjectName.SettingManagement.csproj b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName.CompanyName.ProjectName.SettingManagement.csproj new file mode 100644 index 000000000..51af57d0b --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName.CompanyName.ProjectName.SettingManagement.csproj @@ -0,0 +1,27 @@ + + + + + + + net8.0 + PackageName.CompanyName.ProjectName.SettingManagement + PackageName.CompanyName.ProjectName.SettingManagement + false + false + false + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/IProjectNameSettingAppService.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/IProjectNameSettingAppService.cs new file mode 100644 index 000000000..dff74dddb --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/IProjectNameSettingAppService.cs @@ -0,0 +1,7 @@ +using LINGYUN.Abp.SettingManagement; + +namespace PackageName.CompanyName.ProjectName.SettingManagement; + +public interface IProjectNameSettingAppService : ISettingAppService, IUserSettingAppService +{ +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingAppService.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingAppService.cs new file mode 100644 index 000000000..4fab9bdd6 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingAppService.cs @@ -0,0 +1,106 @@ +using LINGYUN.Abp.SettingManagement; +using Microsoft.AspNetCore.Authorization; +using PackageName.CompanyName.ProjectName.Permissions; +using PackageName.CompanyName.ProjectName.Localization; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Features; +using Volo.Abp.MultiTenancy; +using Volo.Abp.SettingManagement; +using Volo.Abp.Settings; +using Volo.Abp.Users; + +namespace PackageName.CompanyName.ProjectName.SettingManagement; + +public class ProjectNameSettingAppService : ApplicationService, IProjectNameSettingAppService +{ + protected ISettingManager SettingManager { get; } + protected ISettingDefinitionManager SettingDefinitionManager { get; } + + public ProjectNameSettingAppService( + ISettingManager settingManager, + ISettingDefinitionManager settingDefinitionManager) + { + SettingManager = settingManager; + SettingDefinitionManager = settingDefinitionManager; + LocalizationResource = typeof(ProjectNameResource); + } + + public virtual async Task GetAllForCurrentTenantAsync() + { + return await GetAllForProviderAsync(TenantSettingValueProvider.ProviderName, CurrentTenant.GetId().ToString()); + } + + [Authorize] + public virtual async Task GetAllForCurrentUserAsync() + { + return await GetAllForProviderAsync(UserSettingValueProvider.ProviderName, CurrentUser.GetId().ToString()); + } + + public virtual async Task GetAllForGlobalAsync() + { + return await GetAllForProviderAsync(GlobalSettingValueProvider.ProviderName, null); + } + + [Authorize(ProjectNamePermissions.ManageSettings)] + public virtual async Task SetCurrentTenantAsync(UpdateSettingsDto input) + { + // 增加特性检查 + await CheckFeatureAsync(); + + if (CurrentTenant.IsAvailable) + { + foreach (var setting in input.Settings) + { + await SettingManager.SetForTenantAsync(CurrentTenant.GetId(), setting.Name, setting.Value); + } + + await CurrentUnitOfWork.SaveChangesAsync(); + } + } + + [Authorize] + public virtual async Task SetCurrentUserAsync(UpdateSettingsDto input) + { + // 增加特性检查 + await CheckFeatureAsync(); + + foreach (var setting in input.Settings) + { + await SettingManager.SetForCurrentUserAsync(setting.Name, setting.Value); + } + + await CurrentUnitOfWork.SaveChangesAsync(); + } + + [Authorize(ProjectNamePermissions.ManageSettings)] + public virtual async Task SetGlobalAsync(UpdateSettingsDto input) + { + // 增加特性检查 + await CheckFeatureAsync(); + + foreach (var setting in input.Settings) + { + await SettingManager.SetGlobalAsync(setting.Name, setting.Value); + } + + await CurrentUnitOfWork.SaveChangesAsync(); + } + + + protected virtual async Task CheckFeatureAsync() + { + await FeatureChecker.CheckEnabledAsync(SettingManagementFeatures.Enable); + } + + protected virtual async Task GetAllForProviderAsync(string providerName, string providerKey) + { + var settingGroups = new SettingGroupResult(); + + //TODO: 当前项目所有配置项在此定义返回 + + await Task.CompletedTask; + + return settingGroups; + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingController.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingController.cs new file mode 100644 index 000000000..2c045ba59 --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingController.cs @@ -0,0 +1,69 @@ +using Asp.Versioning; +using LINGYUN.Abp.SettingManagement; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using PackageName.CompanyName.ProjectName.Permissions; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; + +namespace PackageName.CompanyName.ProjectName.SettingManagement; + +[RemoteService(Name = ProjectNameRemoteServiceConsts.RemoteServiceName)] +[ApiVersion("2.0")] +[Area(ProjectNameRemoteServiceConsts.ModuleName)] +[Route("api/ProjectName/settings")] +public class ProjectNameSettingController : AbpController, IProjectNameSettingAppService +{ + private readonly IProjectNameSettingAppService _settingAppService; + public ProjectNameSettingController(IProjectNameSettingAppService settingAppService) + { + _settingAppService = settingAppService; + } + + [Authorize(ProjectNamePermissions.ManageSettings)] + [HttpPut] + [Route("by-current-tenant")] + public virtual async Task SetCurrentTenantAsync(UpdateSettingsDto input) + { + await _settingAppService.SetCurrentTenantAsync(input); + } + + [HttpGet] + [Route("by-current-tenant")] + public virtual async Task GetAllForCurrentTenantAsync() + { + return await _settingAppService.GetAllForCurrentTenantAsync(); + } + + [Authorize] + [HttpPut] + [Route("by-current-user")] + public virtual async Task SetCurrentUserAsync(UpdateSettingsDto input) + { + await _settingAppService.SetCurrentTenantAsync(input); + } + + [Authorize] + [HttpGet] + [Route("by-current-user")] + public virtual async Task GetAllForCurrentUserAsync() + { + return await _settingAppService.GetAllForCurrentTenantAsync(); + } + + [Authorize(ProjectNamePermissions.ManageSettings)] + [HttpPut] + [Route("by-global")] + public virtual async Task SetGlobalAsync(UpdateSettingsDto input) + { + await _settingAppService.SetGlobalAsync(input); + } + + [HttpGet] + [Route("by-global")] + public virtual async Task GetAllForGlobalAsync() + { + return await _settingAppService.GetAllForGlobalAsync(); + } +} diff --git a/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingManagementModule.cs b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingManagementModule.cs new file mode 100644 index 000000000..914707f4a --- /dev/null +++ b/aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.SettingManagement/PackageName/CompanyName/ProjectName/SettingManagement/ProjectNameSettingManagementModule.cs @@ -0,0 +1,22 @@ +using LINGYUN.Abp.SettingManagement; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Modularity; +using Volo.Abp.SettingManagement; + +namespace PackageName.CompanyName.ProjectName.SettingManagement; + +[DependsOn( + typeof(AbpSettingManagementApplicationContractsModule), + typeof(AbpAspNetCoreMvcModule), + typeof(AbpSettingManagementDomainModule))] +public class ProjectNameSettingManagementModule : AbpModule +{ + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(mvcBuilder => + { + mvcBuilder.AddApplicationPartIfNotExists(typeof(ProjectNameSettingManagementModule).Assembly); + }); + } +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName.CompanyName.ProjectName.Application.Tests.csproj b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName.CompanyName.ProjectName.Application.Tests.csproj new file mode 100644 index 000000000..7aefab82c --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName.CompanyName.ProjectName.Application.Tests.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + + false + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestBase.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestBase.cs new file mode 100644 index 000000000..f5ae45141 --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestBase.cs @@ -0,0 +1,5 @@ +namespace PackageName.CompanyName.ProjectName; + +public abstract class ProjectNameApplicationTestBase : ProjectNameTestBase +{ +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestModule.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestModule.cs new file mode 100644 index 000000000..7e9fa658a --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Application.Tests/PackageName/CompanyName/ProjectName/ProjectNameApplicationTestModule.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(ProjectNameDomainTestModule), + typeof(ProjectNameApplicationModule) + )] +public class ProjectNameApplicationTestModule : AbpModule +{ +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName.CompanyName.ProjectName.Domain.Tests.csproj b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName.CompanyName.ProjectName.Domain.Tests.csproj new file mode 100644 index 000000000..5ca01ede0 --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName.CompanyName.ProjectName.Domain.Tests.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + + false + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestBase.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestBase.cs new file mode 100644 index 000000000..471e0adf8 --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestBase.cs @@ -0,0 +1,5 @@ +namespace PackageName.CompanyName.ProjectName; + +public abstract class ProjectNameDomainTestBase : ProjectNameTestBase +{ +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestModule.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestModule.cs new file mode 100644 index 000000000..f4a8a9d16 --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.Domain.Tests/PackageName/CompanyName/ProjectName/ProjectNameDomainTestModule.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(ProjectNameTestBaseModule), + typeof(ProjectNameDomainModule) + )] +public class ProjectNameDomainTestModule : AbpModule +{ +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests.csproj b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests.csproj new file mode 100644 index 000000000..cb9c91e1f --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + + false + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestBase.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestBase.cs new file mode 100644 index 000000000..738149b6f --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestBase.cs @@ -0,0 +1,5 @@ +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +public abstract class ProjectNameEntityFrameworkCoreTestBase : ProjectNameTestBase +{ +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestModule.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestModule.cs new file mode 100644 index 000000000..da8ce7c6c --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.EntityFrameworkCore.Tests/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameEntityFrameworkCoreTestModule.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using System; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Modularity; +using Volo.Abp.Uow; + +namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; + +[DependsOn( + typeof(ProjectNameTestBaseModule), + typeof(ProjectNameEntityFrameworkCoreModule) + )] +public class ProjectNameEntityFrameworkCoreTestModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddEntityFrameworkInMemoryDatabase(); + + var databaseName = Guid.NewGuid().ToString(); + + Configure(options => + { + options.Configure(abpDbContextConfigurationContext => + { + abpDbContextConfigurationContext.DbContextOptions.EnableDetailedErrors(); + abpDbContextConfigurationContext.DbContextOptions.EnableSensitiveDataLogging(); + + abpDbContextConfigurationContext.DbContextOptions.UseInMemoryDatabase(databaseName); + }); + }); + + Configure(options => + { + options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions + }); + } +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName.CompanyName.ProjectName.TestBase.csproj b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName.CompanyName.ProjectName.TestBase.csproj new file mode 100644 index 000000000..ae4b6d5bf --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName.CompanyName.ProjectName.TestBase.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + + false + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBase.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBase.cs new file mode 100644 index 000000000..08aeffccb --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBase.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Modularity; +using Volo.Abp.Testing; +using Volo.Abp.Uow; + +namespace PackageName.CompanyName.ProjectName; + +public abstract class ProjectNameTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + + protected virtual Task WithUnitOfWorkAsync(Func func) + { + return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); + } + + protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func action) + { + using (var scope = ServiceProvider.CreateScope()) + { + var uowManager = scope.ServiceProvider.GetRequiredService(); + + using (var uow = uowManager.Begin(options)) + { + await action(); + + await uow.CompleteAsync(); + } + } + } + + protected virtual Task WithUnitOfWorkAsync(Func> func) + { + return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); + } + + protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func> func) + { + using (var scope = ServiceProvider.CreateScope()) + { + var uowManager = scope.ServiceProvider.GetRequiredService(); + + using (var uow = uowManager.Begin(options)) + { + var result = await func(); + await uow.CompleteAsync(); + return result; + } + } + } +} diff --git a/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBaseModule.cs b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBaseModule.cs new file mode 100644 index 000000000..4564d29b6 --- /dev/null +++ b/aspnet-core/templates/micro/content/tests/PackageName.CompanyName.ProjectName.TestBase/PackageName/CompanyName/ProjectName/ProjectNameTestBaseModule.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Authorization; +using Volo.Abp.Autofac; +using Volo.Abp.Features; +using Volo.Abp.MemoryDb; +using Volo.Abp.Modularity; + +namespace PackageName.CompanyName.ProjectName; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpAuthorizationModule), + typeof(AbpFeaturesModule), + typeof(AbpMemoryDbModule) + )] +public class ProjectNameTestBaseModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAlwaysAllowAuthorization(); + } +}