Browse Source

refactor: 优化share host

aspnetcore
zzzwangjun@gmail.com 8 months ago
parent
commit
456e6c621d
  1. 7
      aspnet-core/Lion.AbpPro.sln
  2. 2
      aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion.AbpPro.AspNetCore.csproj
  3. 5
      aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion/AbpPro/AspNetCore/AbpProAspNetCoreConsts.cs
  4. 7
      aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion/AbpPro/AspNetCore/AbpProAspNetCoreModule.cs
  5. 17
      aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs
  6. 14
      aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Serilog/SerilogToEsExtensions.cs
  7. 10
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/GlobalUsings.cs
  8. 12
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion.AbpPro.Hangfire.csproj
  9. 2
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/AutoDeleteAfterSuccessAttribute.cs
  10. 77
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/CronType.cs
  11. 10
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/CustomHangfireAuthorizeFilter.cs
  12. 9
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/IRecurringJob.cs
  13. 4
      aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/JobRetryLastFilter.cs
  14. 5
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs
  15. 76
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs
  16. 78
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs
  17. 11
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs
  18. 15
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs
  19. 3
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs
  20. 32
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj
  21. 9
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs
  22. 61
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.Production.json
  23. 27
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json
  24. 11
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Jobs/IRecurringJob.cs
  25. 1
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Lion.AbpPro.Application.Contracts.csproj
  26. 11
      aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs
  27. 2
      aspnet-core/services/src/Lion.AbpPro.DbMigrator/appsettings.json

7
aspnet-core/Lion.AbpPro.sln

@ -251,6 +251,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.HttpClient", "f
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.AspNetCore", "frameworks\src\Lion.AbpPro.AspNetCore\Lion.AbpPro.AspNetCore.csproj", "{89CCAEA6-8176-4E4B-8D84-A2ACE2715F88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.Hangfire", "frameworks\src\Lion.AbpPro.Hangfire\Lion.AbpPro.Hangfire.csproj", "{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -617,6 +619,10 @@ Global
{89CCAEA6-8176-4E4B-8D84-A2ACE2715F88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89CCAEA6-8176-4E4B-8D84-A2ACE2715F88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89CCAEA6-8176-4E4B-8D84-A2ACE2715F88}.Release|Any CPU.Build.0 = Release|Any CPU
{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -737,6 +743,7 @@ Global
{A70659A2-91F4-4FE7-80D0-DA12430543FD} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{9C88C5AE-21A1-4A62-9FA3-173806CD9EE3} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{89CCAEA6-8176-4E4B-8D84-A2ACE2715F88} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{6C2FDD3D-F711-46B0-A2F2-B94BC33F136B} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}

2
aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion.AbpPro.AspNetCore.csproj

@ -33,7 +33,7 @@
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" />
<PackageReference Include="Serilog.Sinks.Async" />
</ItemGroup>
<ItemGroup>

5
aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion/AbpPro/AspNetCore/AbpProAspNetCoreConsts.cs

@ -41,4 +41,9 @@ public class AbpProAspNetCoreConsts
/// 审计配置节名称
/// </summary>
public const string Audit = "Audit";
/// <summary>
/// token
/// </summary>
public const string Jwt = "Jwt";
}

7
aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Lion/AbpPro/AspNetCore/AbpProAspNetCoreModule.cs

@ -6,17 +6,12 @@ public class AbpProAspNetCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var s = context.Configuration.GetSection(AbpProAspNetCoreConsts.Cors);
context.Services.Configure<AbpProGatewayOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.Gateway));
context.Services.Configure<AbpProCorsOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.Cors));
context.Services.Configure<AbpProMiniProfilerOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.MiniProfiler));
context.Services.Configure<AbpProMultiTenancyOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.MultiTenancy));
context.Services.Configure<AbpProSwaggerOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.Swagger));
context.Services.Configure<AbpProAuditOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.Audit));
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Configure<AbpProJwtOptions>(context.Configuration.GetSection(AbpProAspNetCoreConsts.Jwt));
}
}

17
aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs

@ -30,7 +30,7 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddAbpProConsul(this IServiceCollection service)
{
var consulOptions = service.GetRequiredService<IOptions<AbpProGatewayOptions>>().Value;
var consulOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProGatewayOptions>>().Value;
if (!consulOptions.Enabled)
return service;
@ -46,6 +46,7 @@ public static class ServiceCollectionExtensions
{
// TODO 检查数据库和redis是否正常 AspNetCore.HealthChecks.Redis AspNetCore.HealthChecks.MySql
// context.Services.AddHealthChecks().AddRedis(redisConnectionString).AddMySql(connectString);
service.AddHealthChecks();
return service;
}
@ -94,7 +95,7 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProCors(this IServiceCollection service)
{
var corsOptions = service.GetRequiredService<IOptions<AbpProCorsOptions>>().Value;
var corsOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProCorsOptions>>().Value;
if (!corsOptions.Enabled) return service;
service.AddCors(options =>
@ -150,7 +151,7 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProSwagger(this IServiceCollection service, string name, string version = "v1")
{
var swaggerOptions = service.GetRequiredService<IOptions<AbpProSwaggerOptions>>().Value;
var swaggerOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProSwaggerOptions>>().Value;
if (!swaggerOptions.Enabled) return service;
service.AddSwaggerGen(options =>
@ -221,9 +222,9 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProMiniProfiler(this IServiceCollection service)
{
var options = service.GetRequiredService<IOptions<AbpProMiniProfilerOptions>>().Value;
var options = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProMiniProfilerOptions>>().Value;
if (!options.Enabled) return service;
service.AddMiniProfiler(opt => opt.RouteBasePath = "/profiler").AddEntityFramework();
service.AddMiniProfiler(opt => opt.RouteBasePath = options.RouteBasePath).AddEntityFramework();
return service;
}
@ -232,7 +233,7 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProMultiTenancy(this IServiceCollection service)
{
var multiTenancyOptions = service.GetRequiredService<IOptions<AbpProMultiTenancyOptions>>().Value;
var multiTenancyOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProMultiTenancyOptions>>().Value;
service.Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = multiTenancyOptions.Enabled; });
return service;
}
@ -242,7 +243,7 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProAuthentication(this IServiceCollection service)
{
var jwtOptions = service.GetRequiredService<IOptions<AbpProJwtOptions>>().Value;
var jwtOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProJwtOptions>>().Value;
service.AddAuthentication(options =>
{
@ -315,7 +316,7 @@ public static class ServiceCollectionExtensions
/// </summary>
public static IServiceCollection AddAbpProAuditLog(this IServiceCollection service)
{
var auditOptions = service.GetRequiredService<IOptions<AbpProAuditOptions>>().Value;
var auditOptions = service.BuildServiceProvider().GetRequiredService<IOptions<AbpProAuditOptions>>().Value;
service.Configure<AbpAuditingOptions>
(options =>
{

14
aspnet-core/frameworks/src/Lion.AbpPro.AspNetCore/Serilog/SerilogToEsExtensions.cs

@ -8,30 +8,32 @@ public static class SerilogToEsExtensions
loggerConfiguration
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext();
var writeToSections = configuration.GetSection("Serilog:WriteTo").GetChildren();
var elasticSection = writeToSections.FirstOrDefault(s => s.GetValue<string>("Name") == "Elastic");
var writeToElasticSearch = configuration.GetValue("ElasticSearch:Enabled", false);
var writeToElasticSearch = elasticSection?.GetSection("Args").GetValue<bool>("Enabled") ?? false;
// LogToElasticSearch:Enabled = true 才输出至ES
if (!writeToElasticSearch)
return;
var applicationName = "Lion.AbpPro.HttpApi.Host";
var applicationName = elasticSection?.GetSection("Args").GetValue<string>("ApplicationName") ?? string.Empty;
var esUrl = configuration["ElasticSearch:Url"];
var esUrl = elasticSection?.GetSection("Args").GetValue<string>("Url");
// 需要设置ES URL
if (string.IsNullOrEmpty(esUrl))
return;
var indexFormat = configuration["ElasticSearch:IndexFormat"];
var indexFormat = elasticSection?.GetSection("Args").GetValue<string>("IndexFormat");
// 需要设置ES URL
if (string.IsNullOrEmpty(indexFormat))
return;
var esUserName = configuration["ElasticSearch:UserName"];
var esPassword = configuration["ElasticSearch:Password"];
var esUserName = elasticSection?.GetSection("Args").GetValue<string>("UserName");
var esPassword = elasticSection?.GetSection("Args").GetValue<string>("Password");
loggerConfiguration.Enrich.FromLogContext().Enrich.WithExceptionDetails().WriteTo
.Elasticsearch(BuildElasticSearchSinkOptions(esUrl, indexFormat, esUserName, esPassword));

10
aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/GlobalUsings.cs

@ -0,0 +1,10 @@
// Global using directives
global using Hangfire;
global using Hangfire.Common;
global using Hangfire.Dashboard;
global using Hangfire.States;
global using Hangfire.Storage;
global using Microsoft.Extensions.DependencyInjection;
global using Volo.Abp.DependencyInjection;
global using Volo.Abp.Users;

12
aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion.AbpPro.Hangfire.csproj

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.BackgroundJobs.HangFire" />
</ItemGroup>
</Project>

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttribute.cs → aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/AutoDeleteAfterSuccessAttribute.cs

@ -1,4 +1,4 @@
namespace Lion.AbpPro.Extensions.Hangfire;
namespace Lion.AbpPro.Hangfire;
public class AutoDeleteAfterSuccessAttribute : JobFilterAttribute, IApplyStateFilter
{

77
aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/CronType.cs

@ -0,0 +1,77 @@
namespace Lion.AbpPro.Hangfire;
/// <summary>
/// Cron类型
/// </summary>
public static class CronType
{
/// <summary>
/// 周期性为分钟的任务
/// </summary>
/// <param name="interval">执行周期的间隔,默认为每分钟一次</param>
/// <returns></returns>
public static string Minute(int interval = 1)
{
return "1 0/" + interval.ToString() + " * * * ? ";
}
/// <summary>
/// 周期性为小时的任务
/// </summary>
/// <param name="minute">第几分钟开始,默认为第一分钟</param>
/// <param name="interval">执行周期的间隔,默认为每小时一次</param>
/// <returns></returns>
public static string Hour(int minute = 1, int interval = 1)
{
return "1 " + minute + " 0/" + interval.ToString() + " * * ? ";
}
/// <summary>
/// 周期性为天的任务
/// </summary>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <param name="interval">执行周期的间隔,默认为每天一次</param>
/// <returns></returns>
public static string Day(int hour = 1, int minute = 1, int interval = 1)
{
return "1 " + minute.ToString() + " " + hour.ToString() + " 1/" + interval.ToString() + " * ? ";
}
/// <summary>
/// 周期性为周的任务
/// </summary>
/// <param name="dayOfWeek">星期几开始,默认从星期一点开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Week(DayOfWeek dayOfWeek = DayOfWeek.Monday, int hour = 1, int minute = 1)
{
return Cron.Weekly(dayOfWeek, hour, minute);
}
/// <summary>
/// 周期性为月的任务
/// </summary>
/// <param name="day">几号开始,默认从一号开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Month(int day = 1, int hour = 1, int minute = 1)
{
return Cron.Monthly(day, hour, minute);
}
/// <summary>
/// 周期性为年的任务
/// </summary>
/// <param name="month">几月开始,默认从一月开始</param>
/// <param name="day">几号开始,默认从一号开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Year(int month = 1, int day = 1, int hour = 1, int minute = 1)
{
return Cron.Yearly(month, day, hour, minute);
}
}

10
aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/CustomHangfireAuthorizeFilter.cs

@ -0,0 +1,10 @@
namespace Lion.AbpPro.Hangfire;
public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
var currentUser = context.GetHttpContext().RequestServices.GetRequiredService<ICurrentUser>();
return currentUser.IsAuthenticated;
}
}

9
aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/IRecurringJob.cs

@ -0,0 +1,9 @@
namespace Lion.AbpPro.Hangfire;
public interface IRecurringJob : ITransientDependency
{
/// <summary>
/// 执行任务
/// </summary>
Task ExecuteAsync();
}

4
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs → aspnet-core/frameworks/src/Lion.AbpPro.Hangfire/Lion/AbpPro/Hangfire/JobRetryLastFilter.cs

@ -1,4 +1,4 @@
namespace Lion.AbpPro.Extensions.Hangfire;
namespace Lion.AbpPro.Hangfire;
/// <summary>
/// 重试最后一次
@ -18,7 +18,7 @@ public class JobRetryLastFilter : JobFilterAttribute, IElectStateFilter
var retryAttempt = context.GetJobParameter<int>("RetryCount");
if (RetryCount == retryAttempt)
{
Log.Error("最后一次重试");
// 最后一次重试
}
}
}

5
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs

@ -1,5 +1,5 @@
namespace Lion.AbpPro
{
namespace Lion.AbpPro;
public static class AbpProHttpApiHostConst
{
/// <summary>
@ -37,4 +37,3 @@ namespace Lion.AbpPro
public const string MiniprofilerEndPoint = "/profiler/results-index";
}
}

76
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs

@ -1,5 +1,5 @@
namespace Lion.AbpPro
{
namespace Lion.AbpPro;
[DependsOn(
typeof(AbpProHttpApiModule),
typeof(AbpProAspNetCoreModule),
@ -15,18 +15,12 @@ namespace Lion.AbpPro
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpDistributedLockingModule),
typeof(AbpBlobStoringFileSystemModule),
typeof(AbpProStarterModule)
typeof(AbpProStarterModule),
typeof(AbpSwashbuckleModule)
//typeof(AbpBackgroundJobsHangfireModule)
)]
public partial class AbpProHttpApiHostModule : AbpModule
{
public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
{
// 应用程序初始化的时候注册hangfire
//context.CreateRecurringJob();
base.OnPostApplicationInitialization(context);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services
@ -47,82 +41,22 @@ namespace Lion.AbpPro
.AddAbpProLocalization()
.AddAbpProExceptions()
.AddAbpProSwagger("AbpPro");
// //ConfigureCache(context);
// context.Services.AddAbpProRedis();
//
// //ConfigurationDistributedLocking(context);
// context.Services.AddAbpProRedisDistributedLocking();
//
//
// //ConfigureSwaggerServices(context);
// context.Services.AddAbpProSwagger("AbpPro");
//
// //ConfigureJwtAuthentication(context, configuration);
// context.Services.AddAbpProAuthentication();
//
// //ConfigureHangfire(context);
//
// //ConfigureMiniProfiler(context);
// context.Services.AddAbpProMiniProfiler();
//
// //ConfigureIdentity(context);
// context.Services.AddAbpProIdentity();
//
// //ConfigureCap(context);
//
// //ConfigureAuditLog(context);
// context.Services.AddAbpProAuditLog();
//
// //ConfigurationSignalR(context);
// context.Services.AddAbpProSignalR();
//
// //ConfigurationMultiTenancy();
// context.Services.AddAbpProMultiTenancy();
//
// //ConfigureBlobStorage();
// context.Services.AddAbpProBlobStorage();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
//var configuration = context.GetConfiguration();
app.UseAbpProRequestLocalization();
app.UseCorrelationId();
app.MapAbpStaticAssets();
// if (configuration.GetValue("MiniProfiler:Enabled", false))
// {
// app.UseMiniProfiler();
// }
app.UseAbpProMiniProfiler();
app.UseRouting();
//app.UseCors(AbpProHttpApiHostConst.DefaultCorsPolicyName);
app.UseAbpProCors();
app.UseAuthentication();
// if (MultiTenancyConsts.IsEnabled)
// {
// app.UseMultiTenancy();
// }
app.UseAbpProMultiTenancy();
app.UseAuthorization();
// app.UseSwagger();
// app.UseAbpSwaggerUI(options =>
// {
// options.SwaggerEndpoint("/swagger/AbpPro/swagger.json", "AbpPro API");
// options.DocExpansion(DocExpansion.None);
// options.DefaultModelsExpandDepth(-1);
// });
app.UseAbpProSwaggerUI("/swagger/AbpPro/swagger.json","AbpPro");
//app.UseAuditing();
app.UseAbpProAuditing();
app.UseAbpSerilogEnrichers();
app.UseUnitOfWork();
app.UseConfiguredEndpoints(endpoints =>
@ -136,8 +70,6 @@ namespace Lion.AbpPro
// });
});
app.UseAbpProConsul();
}
}
}

78
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs

@ -1,78 +0,0 @@
namespace Lion.AbpPro.Extensions.Hangfire
{
/// <summary>
/// Cron类型
/// </summary>
public static class CronType
{
/// <summary>
/// 周期性为分钟的任务
/// </summary>
/// <param name="interval">执行周期的间隔,默认为每分钟一次</param>
/// <returns></returns>
public static string Minute(int interval = 1)
{
return "1 0/" + interval.ToString() + " * * * ? ";
}
/// <summary>
/// 周期性为小时的任务
/// </summary>
/// <param name="minute">第几分钟开始,默认为第一分钟</param>
/// <param name="interval">执行周期的间隔,默认为每小时一次</param>
/// <returns></returns>
public static string Hour(int minute = 1, int interval = 1)
{
return "1 " + minute + " 0/" + interval.ToString() + " * * ? ";
}
/// <summary>
/// 周期性为天的任务
/// </summary>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <param name="interval">执行周期的间隔,默认为每天一次</param>
/// <returns></returns>
public static string Day(int hour = 1, int minute = 1, int interval = 1)
{
return "1 " + minute.ToString() + " " + hour.ToString() + " 1/" + interval.ToString() + " * ? ";
}
/// <summary>
/// 周期性为周的任务
/// </summary>
/// <param name="dayOfWeek">星期几开始,默认从星期一点开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Week(DayOfWeek dayOfWeek = DayOfWeek.Monday, int hour = 1, int minute = 1)
{
return Cron.Weekly(dayOfWeek, hour, minute);
}
/// <summary>
/// 周期性为月的任务
/// </summary>
/// <param name="day">几号开始,默认从一号开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Month(int day = 1, int hour = 1, int minute = 1)
{
return Cron.Monthly(day, hour, minute);
}
/// <summary>
/// 周期性为年的任务
/// </summary>
/// <param name="month">几月开始,默认从一月开始</param>
/// <param name="day">几号开始,默认从一号开始</param>
/// <param name="hour">第几小时开始,默认从1点开始</param>
/// <param name="minute">第几分钟开始,默认从第1分钟开始</param>
/// <returns></returns>
public static string Year(int month = 1, int day = 1, int hour = 1, int minute = 1)
{
return Cron.Yearly(month, day, hour, minute);
}
}
}

11
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs

@ -1,11 +0,0 @@
namespace Lion.AbpPro.Extensions.Hangfire
{
public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
var _currentUser = context.GetHttpContext().RequestServices.GetRequiredService<ICurrentUser>();
return _currentUser.IsAuthenticated;
}
}
}

15
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs

@ -1,15 +0,0 @@
using Lion.AbpPro.Jobs;
namespace Lion.AbpPro.Extensions.Hangfire
{
public static class RecurringJobsExtensions
{
public static void CreateRecurringJob(this ApplicationInitializationContext context)
{
RecurringJob.AddOrUpdate<TestJob>("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions()
{
TimeZone = TimeZoneInfo.Local
});
}
}
}

3
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs

@ -21,8 +21,6 @@ global using Lion.AbpPro.CAP;
global using Lion.AbpPro.CAP.EntityFrameworkCore;
global using Lion.AbpPro.EntityFrameworkCore;
global using Lion.AbpPro.Core;
global using Lion.AbpPro.Extensions;
global using Lion.AbpPro.Extensions.Hangfire;
global using Lion.AbpPro.MultiTenancy;
global using Lion.AbpPro.Starter;
global using Magicodes.ExporterAndImporter.Core;
@ -80,5 +78,6 @@ global using Volo.Abp.Json;
global using Volo.Abp.Localization;
global using Volo.Abp.Modularity;
global using Volo.Abp.MultiTenancy;
global using Volo.Abp.Swashbuckle;
global using Volo.Abp.Users;
global using Volo.Abp.Validation;

32
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj

@ -1,6 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>Lion.AbpPro</RootNamespace>
@ -8,39 +6,27 @@
<UserSecretsId>Lion.AbpPro-4681b4fd-151f-4221-84a4-929d86723e4c</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" />
<PackageReference Include="Volo.Abp.Account.Web"/>
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy"/>
<PackageReference Include="Volo.Abp.Autofac" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis"/>
<PackageReference Include="Volo.Abp.AspNetCore.Serilog"/>
<PackageReference Include="Volo.Abp.Swashbuckle"/>
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer"/>
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic"/>
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Serilog.Exceptions" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Settings.Configuration" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Serilog.Sinks.Async" />
<PackageReference Include="Hangfire.Redis.StackExchange" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" />
<PackageReference Include="Volo.Abp.DistributedLocking"/>
<PackageReference Include="Volo.Abp.BlobStoring.FileSystem"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis"/>
<PackageReference Include="DotNetCore.CAP.MySql"/>
<PackageReference Include="DotNetCore.CAP.RabbitMQ"/>
<PackageReference Include="DotNetCore.CAP.Dashboard"/>
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" />
<PackageReference Include="MiniProfiler.EntityFrameworkCore" />
<PackageReference Include="MiniProfiler.Shared" />
<PackageReference Include="Volo.Abp.BackgroundJobs.HangFire" />
<PackageReference Include="Volo.Abp.DistributedLocking"/>
<PackageReference Include="DistributedLock.Redis"/>
<PackageReference Include="Volo.Abp.BlobStoring.FileSystem" />
<PackageReference Include="Hangfire.Redis.StackExchange"/>
</ItemGroup>
<ItemGroup>

9
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs

@ -1,4 +1,6 @@
#pragma warning disable CS0618 // Type or member is obsolete
using Lion.AbpPro.Hangfire;
#pragma warning disable CS0618 // Type or member is obsolete
namespace Microsoft.Extensions.DependencyInjection;
@ -99,14 +101,13 @@ public static class ServiceCollectionExtensions
service.AddHangfire(config =>
{
config.UseRedisStorage(
service.GetConfiguration().GetValue<string>("Hangfire:Redis:Host"), redisStorageOptions)
config.UseRedisStorage(service.GetConfiguration().GetValue<string>("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));
//config.UseFilter(new JobRetryLastFilter(attempts));
});
return service;
}

61
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.Production.json

@ -5,7 +5,7 @@
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Information",
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"Volo.Abp": "Information",
@ -26,25 +26,35 @@
"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": "http://localhost:80,http://43.139.143.143:80,http://43.139.143.143"
},
"ConnectionStrings": {
"Default": "Data Source=mysql;Port=3306;Database=LionAbpProDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
},
"Redis": {
"Configuration": "redis:6379,password=1q2w3E*,defaultdatabase=3"
"Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=f616b8803ac7a9a0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
},
"Hangfire": {
"Redis": {
"Host": "redis:6379,password=1q2w3E*",
"Host": "localhost:6379,password=1q2w3E*",
"DB": "2"
}
},
"Redis": {
"Configuration": "localhost:6379,password=75He82bB5jFA84XZ1,defaultdatabase=2"
},
"Jwt": {
"Audience": "Lion.AbpPro",
"SecurityKey": "dzehzRz9a8asdfasfdadfasdfasdfafsdadfasbasdf=",
@ -53,23 +63,40 @@
},
"Cap": {
"RabbitMq": {
"HostName": "rabbitmq",
"HostName": "localhost",
"UserName": "admin",
"Password": "1q2w3E*",
"Port": 5672
}
},
"ElasticSearch": {
"Enabled": false,
"Url": "http://es.cn",
"IndexFormat": "Lion.AbpPro.development.{0:yyyy.MM.dd}",
"Host": "http://es.cn",
"UserName": "elastic",
"Password": "aVVhjQ95RP7nbwNy",
"SearchIndexFormat": "Lion.AbpPro.development*"
"Password": "aVVhjQ95RP7nbwNy"
},
"Consul": {
"Enabled": false,
"Host": "http://localhost:8500",
"Service": "Project-Service"
"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"
}
}

27
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json

@ -26,24 +26,34 @@
"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://*.AbpPro.com,http://localhost:4200,http://localhost:44320,http://localhost:44321,http://localhost:44322,http://localhost:44318"
},
"ConnectionStrings": {
"Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;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": "117.72.203.231:6379,password=1q2w3E*",
"Host": "localhost:6379,password=1q2w3E*",
"DB": "2"
}
},
"Redis": {
"Configuration": "117.72.203.231:6379,password=75He82bB5jFA84XZ1,defaultdatabase=2"
"Configuration": "localhost:6379,password=75He82bB5jFA84XZ1,defaultdatabase=2"
},
"Jwt": {
"Audience": "Lion.AbpPro",
@ -60,16 +70,13 @@
}
},
"ElasticSearch": {
"Enabled": false,
"Url": "http://es.cn",
"IndexFormat": "Lion.AbpPro.development.{0:yyyy.MM.dd}",
"Host": "http://es.cn",
"UserName": "elastic",
"Password": "aVVhjQ95RP7nbwNy",
"SearchIndexFormat": "Lion.AbpPro.development*"
"Password": "aVVhjQ95RP7nbwNy"
},
"MiniProfiler": {
"Enabled": true,
"RouteBasePath": "profiler"
"RouteBasePath": "/profiler"
},
"Swagger": {
"Enabled": true

11
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Jobs/IRecurringJob.cs

@ -1,11 +0,0 @@
namespace Lion.AbpPro.Jobs
{
public interface IRecurringJob : ITransientDependency
{
/// <summary>
/// 执行任务
/// </summary>
/// <returns></returns>
Task ExecuteAsync();
}
}

1
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Lion.AbpPro.Application.Contracts.csproj

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\frameworks\src\Lion.AbpPro.Hangfire\Lion.AbpPro.Hangfire.csproj" />
<ProjectReference Include="..\..\..\modules\BasicManagement\src\Lion.AbpPro.BasicManagement.Application.Contracts\Lion.AbpPro.BasicManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\DataDictionaryManagement\src\Lion.AbpPro.DataDictionaryManagement.Application.Contracts\Lion.AbpPro.DataDictionaryManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\FileManagement\src\Lion.AbpPro.FileManagement.Application.Contracts\Lion.AbpPro.FileManagement.Application.Contracts.csproj" />

11
aspnet-core/services/src/Lion.AbpPro.Application/Jobs/TestJob.cs

@ -1,11 +0,0 @@
namespace Lion.AbpPro.Jobs
{
public class TestJob : IRecurringJob
{
public Task ExecuteAsync()
{
Console.WriteLine($"job 测试");
return Task.CompletedTask;
}
}
}

2
aspnet-core/services/src/Lion.AbpPro.DbMigrator/appsettings.json

@ -1,5 +1,5 @@
{
"ConnectionStrings": {
"Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
"Default": "Data Source=117.72.203.231;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=f616b8803ac7a9a0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
}
}
Loading…
Cancel
Save