From 3d924c3151bfcde3ec287ffa4a597ad1e634bbfa Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 18 Dec 2020 15:54:40 +0800 Subject: [PATCH 1/2] Set job display name --- .../AbpBackgroundJobsHangfireModule.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs index 8e6802e751..2475078a66 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Hangfire; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -13,6 +14,21 @@ namespace Volo.Abp.BackgroundJobs.Hangfire )] public class AbpBackgroundJobsHangfireModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddTransient(serviceProvider => + { + return new DashboardOptions + { + DisplayNameFunc = (_, job) => + { + var backgroundJobOptions = serviceProvider.GetRequiredService>().Value; + return backgroundJobOptions.GetJob(job.Args.First().GetType()).JobName; + } + }; + }); + } + public override void OnPreApplicationInitialization(ApplicationInitializationContext context) { var options = context.ServiceProvider.GetRequiredService>().Value; @@ -29,4 +45,4 @@ namespace Volo.Abp.BackgroundJobs.Hangfire return null; } } -} \ No newline at end of file +} From a8c2bbce3ee6f318e2fdc91727b1396641980d5e Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 18 Dec 2020 17:25:31 +0800 Subject: [PATCH 2/2] Add AbpDashboardOptionsProvider. --- .../AbpBackgroundJobsHangfireModule.cs | 11 +------- .../Hangfire/AbpDashboardOptionsProvider.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs index 2475078a66..c70c01b246 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs @@ -17,16 +17,7 @@ namespace Volo.Abp.BackgroundJobs.Hangfire public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddTransient(serviceProvider => - { - return new DashboardOptions - { - DisplayNameFunc = (_, job) => - { - var backgroundJobOptions = serviceProvider.GetRequiredService>().Value; - return backgroundJobOptions.GetJob(job.Args.First().GetType()).JobName; - } - }; - }); + serviceProvider.GetRequiredService().Get()); } public override void OnPreApplicationInitialization(ApplicationInitializationContext context) diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs new file mode 100644 index 0000000000..57a055727c --- /dev/null +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs @@ -0,0 +1,26 @@ +using System.Linq; +using Hangfire; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.BackgroundJobs.Hangfire +{ + public class AbpDashboardOptionsProvider : ITransientDependency + { + protected AbpBackgroundJobOptions AbpBackgroundJobOptions { get; } + + public AbpDashboardOptionsProvider(IOptions abpBackgroundJobOptions) + { + AbpBackgroundJobOptions = abpBackgroundJobOptions.Value; + } + + public virtual DashboardOptions Get() + { + return new DashboardOptions + { + DisplayNameFunc = (dashboardContext, job) => + AbpBackgroundJobOptions.GetJob(job.Args.First().GetType()).JobName + }; + } + } +}