Merge pull request #17422 from abpframework/auto-merge/rel-7-4/2132

Merge branch dev with rel-7.4
pull/17423/head
maliming 2 years ago committed by GitHub
commit db551080e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,7 +70,7 @@ After you have installed these NuGet packages, you need to configure your projec
> You have to configure a storage for Hangfire.
2. If you want to use hangfire's dashboard, you can add `UseHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class:
2. If you want to use hangfire's dashboard, you can add `UseAbpHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class:
````csharp
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -79,7 +79,7 @@ After you have installed these NuGet packages, you need to configure your projec
// ... others
app.UseHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints()
app.UseAbpHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints()
app.UseConfiguredEndpoints();
}
````
@ -128,9 +128,9 @@ You can integrate the Hangfire dashboard to [ABP authorization system](Authoriza
class. This class is defined in the `Volo.Abp.Hangfire` package. The following example, checks if the current user is logged in to the application:
```csharp
app.UseHangfireDashboard("/hangfire", new DashboardOptions
app.UseAbpHangfireDashboard("/hangfire", options =>
{
AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }
options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() };
});
```
@ -146,11 +146,11 @@ app.UseHangfireDashboard("/hangfire", new DashboardOptions
If you want to require an additional permission, you can pass it into the constructor as below:
```csharp
app.UseHangfireDashboard("/hangfire", new DashboardOptions
app.UseAbpHangfireDashboard("/hangfire", options =>
{
AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") }
options.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") };
});
```
**Important**: `UseHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise,
**Important**: `UseAbpHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise,
authorization will always fail!

@ -70,7 +70,7 @@ After you have installed these NuGet packages, you need to configure your projec
> You have to configure a storage for Hangfire.
2. If you want to use hangfire's dashboard, you can add `UseHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class
2. If you want to use hangfire's dashboard, you can add `UseAbpHangfireDashboard` call in the `OnApplicationInitialization` method in `Module` class
````csharp
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -79,7 +79,7 @@ After you have installed these NuGet packages, you need to configure your projec
// ... others
app.UseHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints()
app.UseAbpHangfireDashboard(); //should add to the request pipeline before the app.UseConfiguredEndpoints()
app.UseConfiguredEndpoints();
}
````

@ -0,0 +1,20 @@
using System;
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundJobs.Hangfire;
namespace Microsoft.AspNetCore.Builder;
public static class AbpHangfireApplicationBuilderExtensions
{
public static IApplicationBuilder UseAbpHangfireDashboard(
this IApplicationBuilder app,
string pathMatch = "/hangfire",
Action<DashboardOptions>? configure = null,
JobStorage? storage = null)
{
var options = app.ApplicationServices.GetRequiredService<AbpDashboardOptionsProvider>().Get();
configure?.Invoke(options);
return app.UseHangfireDashboard(pathMatch, options, storage);
}
}

@ -1,4 +1,5 @@
using System.Linq;
using System.Threading;
using Hangfire;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -18,8 +19,16 @@ public class AbpDashboardOptionsProvider : ITransientDependency
{
return new DashboardOptions
{
DisplayNameFunc = (dashboardContext, job) =>
AbpBackgroundJobOptions.GetJob(job.Args.First().GetType()).JobName
DisplayNameFunc = (_, job) =>
{
var jobName = job.ToString();
if (job.Args.Count == 3 && job.Args.Last() is CancellationToken)
{
jobName = AbpBackgroundJobOptions.GetJob(job.Args[1].GetType()).JobName;
}
return jobName;
}
};
}
}

Loading…
Cancel
Save