diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/GlobalUsings.cs b/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/GlobalUsings.cs index cf2765ce..01cba018 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/GlobalUsings.cs +++ b/aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/GlobalUsings.cs @@ -5,31 +5,23 @@ global using Ocelot.DependencyInjection; global using Ocelot.Provider.Consul; global using Ocelot.Provider.Polly; global using Volo.Abp.Modularity; - global using System; global using System.Collections.Concurrent; global using System.Collections.Generic; -global using System.Diagnostics.CodeAnalysis; global using System.Linq; global using System.Net; global using System.Reflection; global using System.Text; -global using System.Text.Json; global using System.Threading.Tasks; global using Lion.AbpPro; global using Lion.AbpPro.Core; global using Lion.AbpPro.Localization; -global using Microsoft.AspNetCore.Builder; -global using Microsoft.AspNetCore.Cors; -global using Microsoft.AspNetCore.Hosting; global using Microsoft.AspNetCore.Http; -global using Microsoft.AspNetCore.HttpsPolicy; global using Microsoft.AspNetCore.Mvc; global using Microsoft.AspNetCore.Mvc.Abstractions; global using Microsoft.AspNetCore.Mvc.ApiExplorer; global using Microsoft.EntityFrameworkCore; global using Microsoft.Extensions.Configuration; -global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Hosting; global using Microsoft.Extensions.Localization; global using Microsoft.Extensions.Logging; @@ -42,7 +34,6 @@ global using Serilog.Exceptions; global using Serilog.Sinks.Elasticsearch; global using Swashbuckle.AspNetCore.Swagger; global using Swashbuckle.AspNetCore.SwaggerGen; -global using Volo.Abp; global using Volo.Abp.AspNetCore.ExceptionHandling; global using Volo.Abp.AspNetCore.Mvc; global using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; @@ -52,5 +43,4 @@ global using Volo.Abp.Domain.Entities; global using Volo.Abp.ExceptionHandling; global using Volo.Abp.Http; global using Volo.Abp.Json; -global using Volo.Abp.Modularity; global using Volo.Abp.Validation; \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj index 598c755b..fb5228ce 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj @@ -20,7 +20,6 @@ - diff --git a/templates/pro-nuget/service/Directory.Build.Lion.targets b/templates/pro-nuget/service/Directory.Build.Lion.targets index 4de3630c..212fc211 100644 --- a/templates/pro-nuget/service/Directory.Build.Lion.targets +++ b/templates/pro-nuget/service/Directory.Build.Lion.targets @@ -2,8 +2,7 @@ - - + diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..129f42ce --- /dev/null +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs @@ -0,0 +1,86 @@ +using Hangfire.Redis.StackExchange; +using Medallion.Threading; +using Medallion.Threading.Redis; + +#pragma warning disable CS0618 // Type or member is obsolete + +namespace Microsoft.Extensions.DependencyInjection; + +public static class ServiceCollectionExtensions +{ + /// + /// 注册Redis缓存 + /// + public static IServiceCollection AddAbpProRedis(this IServiceCollection service) + { + service.Configure(options => { options.KeyPrefix = "AbpPro:"; }); + var configuration = service.GetConfiguration(); + var redis = ConnectionMultiplexer.Connect(configuration.GetValue("Redis:Configuration")); + service + .AddDataProtection() + .PersistKeysToStackExchangeRedis(redis, "AbpPro-Protection-Keys"); + return service; + } + + /// + /// 注册redis分布式锁 + /// + public static IServiceCollection AddAbpProRedisDistributedLocking(this IServiceCollection service) + { + var configuration = service.GetConfiguration(); + var connectionString = configuration.GetValue("Redis:Configuration"); + service.AddSingleton(sp => + { + var connection = ConnectionMultiplexer.Connect(connectionString); + return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); + }); + return service; + } + + /// + /// 注册Identity + /// + public static IServiceCollection AddAbpProIdentity(this IServiceCollection service) + { + service.Configure(options => { options.Lockout = new LockoutOptions() { AllowedForNewUsers = false }; }); + return service; + } + + /// + /// 注册SignalR + /// + public static IServiceCollection AddAbpProSignalR(this IServiceCollection service) + { + service + .AddSignalR() + .AddStackExchangeRedis(service.GetConfiguration().GetValue("Redis:Configuration"), + options => { options.Configuration.ChannelPrefix = "Lion.AbpPro"; }); + return service; + } + + + /// + /// 注册hangfire + /// + public static IServiceCollection AddAbpProHangfire(this IServiceCollection service) + { + var redisStorageOptions = new RedisStorageOptions() + { + Db = service.GetConfiguration().GetValue("Hangfire:Redis:DB") + }; + + service.Configure(options => { options.IsJobExecutionEnabled = true; }); + + service.AddHangfire(config => + { + config.UseRedisStorage(service.GetConfiguration().GetValue("Hangfire:Redis:Host"), redisStorageOptions) + .WithJobExpirationTimeout(TimeSpan.FromDays(7)); + var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔 + const int attempts = 3; // 重试次数 + config.UseFilter(new AutomaticRetryAttribute() { Attempts = 3, DelaysInSeconds = delaysInSeconds }); + //config.UseFilter(new AutoDeleteAfterSuccessAttribute(TimeSpan.FromDays(7))); + //config.UseFilter(new JobRetryLastFilter(attempts)); + }); + return service; + } +} \ No newline at end of file diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj index 531778e7..5b786630 100644 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyCompanyName.MyProjectName.HttpApi.Host.csproj @@ -9,35 +9,28 @@ - - - - - - - - - - - - - - - + + + + + + - - - + + + + + diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index ae31d154..3debd6a6 100644 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -39,7 +39,6 @@ namespace MyCompanyName.MyProjectName .AddAbpProCors() .AddAbpProAntiForgery() .AddAbpProIdentity() - .AddAbpProBlobStorage() .AddAbpProSignalR() .AddAbpProHealthChecks() .AddAbpProTenantResolvers() diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.Production.json b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.Production.json index 7816a380..656874b1 100644 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.Production.json +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.Production.json @@ -5,7 +5,7 @@ "Serilog.Sinks.File" ], "MinimumLevel": { - "Default": "Information", + "Default": "Debug", "Override": { "Microsoft": "Information", "Volo.Abp": "Information", @@ -26,31 +26,77 @@ "path": "logs/logs-.txt", "rollingInterval": "Day" } + }, + { + "Name": "Elastic", + "Args": { + "Enabled": false, + "Url": "http://es.cn", + "IndexFormat": "Lion.AbpPro.development.{0:yyyy.MM.dd}", + "UserName": "elastic", + "Password": "aVVhjQ95RP7nbwNy", + "ApplicationName": "Lion.AbpPro.HttpApi.Host" + } } ] }, "App": { "SelfUrl": "http://localhost:44315", - "CorsOrigins": "https://*.MyProjectName.com,http://localhost:4200,http://localhost:3100,http://localhost:80,http://localhost" }, "ConnectionStrings": { - "Default": "Data Source=mysql;Port=3306;Database=MyCompanyNameMyProjectNameDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=f616b8803ac7a9a0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + }, + "Hangfire": { + "Redis": { + "Host": "localhost:6379,password=1q2w3E*", + "DB": "2" + } }, "Redis": { - "Configuration": "localhost,password=1q2w3E*,defaultdatabase=1" + "Configuration": "localhost:6379,password=75He82bB5jFA84XZ1,defaultdatabase=2" }, "Jwt": { - "Audience": "MyCompanyName.MyProjectName", + "Audience": "Lion.AbpPro", "SecurityKey": "dzehzRz9a8asdfasfdadfasdfasdfafsdadfasbasdf=", - "Issuer": "MyCompanyName.MyProjectName", + "Issuer": "Lion.AbpPro", "ExpirationTime": 2 }, + "Cap": { + "RabbitMq": { + "HostName": "localhost", + "UserName": "admin", + "Password": "1q2w3E*", + "Port": 5672 + } + }, "ElasticSearch": { - "Enabled": "false", - "Url": "http://es.cn", - "IndexFormat": "MyCompanyName.MyProjectName.development.{0:yyyy.MM.dd}", + "Host": "http://es.cn", "UserName": "elastic", - "Password": "aVVhjQ95RP7nbwNy", - "SearchIndexFormat": "MyCompanyName.MyProjectName.development*" + "Password": "aVVhjQ95RP7nbwNy" + }, + "MiniProfiler": { + "Enabled": true, + "RouteBasePath": "/profiler" + }, + "Swagger": { + "Enabled": true + }, + "Audit": { + "Enabled": true, + "ApplicationName": "Lion.AbpPro" + }, + "Cors": { + "Enabled": true, + "CorsOrigins": "http://localhost:4200,http://localhost:4201" + }, + "Gateway": { + "Enabled": false + }, + "MultiTenancy": { + "Enabled": true + }, + "Preheat": { + "Enabled": true, + "RequestUrl": "http://localhost:44315/api/abp/application-configuration?IncludeLocalizationResources=false" } } \ No newline at end of file diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json index ade24ccc..656874b1 100644 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json @@ -26,36 +26,77 @@ "path": "logs/logs-.txt", "rollingInterval": "Day" } + }, + { + "Name": "Elastic", + "Args": { + "Enabled": false, + "Url": "http://es.cn", + "IndexFormat": "Lion.AbpPro.development.{0:yyyy.MM.dd}", + "UserName": "elastic", + "Password": "aVVhjQ95RP7nbwNy", + "ApplicationName": "Lion.AbpPro.HttpApi.Host" + } } ] }, "App": { "SelfUrl": "http://localhost:44315", - "CorsOrigins": "https://*.MyProjectName.com,http://localhost:4200,http://localhost:3100" }, "ConnectionStrings": { - "Default": "Data Source=localhost;Port=3306;Database=MyCompanyNameMyProjectNameDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=f616b8803ac7a9a0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + }, + "Hangfire": { + "Redis": { + "Host": "localhost:6379,password=1q2w3E*", + "DB": "2" + } }, "Redis": { - "Configuration": "localhost,password=1q2w3E*,defaultdatabase=1" + "Configuration": "localhost:6379,password=75He82bB5jFA84XZ1,defaultdatabase=2" }, "Jwt": { - "Audience": "MyCompanyName.MyProjectName", + "Audience": "Lion.AbpPro", "SecurityKey": "dzehzRz9a8asdfasfdadfasdfasdfafsdadfasbasdf=", - "Issuer": "MyCompanyName.MyProjectName", + "Issuer": "Lion.AbpPro", "ExpirationTime": 2 }, + "Cap": { + "RabbitMq": { + "HostName": "localhost", + "UserName": "admin", + "Password": "1q2w3E*", + "Port": 5672 + } + }, "ElasticSearch": { - "Enabled": "false", - "Url": "http://es.cn", - "IndexFormat": "MyCompanyName.MyProjectName.development.{0:yyyy.MM.dd}", + "Host": "http://es.cn", "UserName": "elastic", - "Password": "aVVhjQ95RP7nbwNy", - "SearchIndexFormat": "MyCompanyName.MyProjectName.development*" + "Password": "aVVhjQ95RP7nbwNy" + }, + "MiniProfiler": { + "Enabled": true, + "RouteBasePath": "/profiler" + }, + "Swagger": { + "Enabled": true + }, + "Audit": { + "Enabled": true, + "ApplicationName": "Lion.AbpPro" + }, + "Cors": { + "Enabled": true, + "CorsOrigins": "http://localhost:4200,http://localhost:4201" + }, + "Gateway": { + "Enabled": false + }, + "MultiTenancy": { + "Enabled": true }, - "Consul": { - "Enabled": false, - "Host": "http://localhost:8500", - "Service": "Project-Service" + "Preheat": { + "Enabled": true, + "RequestUrl": "http://localhost:44315/api/abp/application-configuration?IncludeLocalizationResources=false" } } \ No newline at end of file diff --git a/templates/pro-nuget/service/src/MyCompanyName.MyProjectName.Domain.Shared/MyCompanyName.MyProjectName.Domain.Shared.csproj b/templates/pro-nuget/service/src/MyCompanyName.MyProjectName.Domain.Shared/MyCompanyName.MyProjectName.Domain.Shared.csproj index 967f58f2..71fc901e 100644 --- a/templates/pro-nuget/service/src/MyCompanyName.MyProjectName.Domain.Shared/MyCompanyName.MyProjectName.Domain.Shared.csproj +++ b/templates/pro-nuget/service/src/MyCompanyName.MyProjectName.Domain.Shared/MyCompanyName.MyProjectName.Domain.Shared.csproj @@ -12,6 +12,7 @@ +