32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using Hangfire;
|
|
using Hangfire.Storage.SQLite;
|
|
|
|
namespace HangfireExample.WebService.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Hangfire 的擴充方法。
|
|
/// </summary>
|
|
public static class HangfireExtension
|
|
{
|
|
/// <summary>
|
|
/// 加入 Hangfire 服務。
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <returns></returns>
|
|
public static IServiceCollection AddHangfire(this IServiceCollection services)
|
|
{
|
|
// 將 Hangfire 加入服務,使用 SQLite 作為儲存區
|
|
services.AddHangfire(configuration => configuration
|
|
.UseSQLiteStorage("HangfireExample.db"));
|
|
return services;
|
|
}
|
|
|
|
public static WebApplication UseHangfireDashboard(this WebApplication app, IConfiguration configuration)
|
|
{
|
|
// HangfireDashboard 預設路由為 /Hangfire
|
|
app.UseHangfireDashboard(configuration.GetValue<string>("DashboardRoot"));
|
|
return app;
|
|
}
|
|
}
|
|
}
|