113/03/12
This commit is contained in:
31
HangfireExample.WebService/Extensions/HangfireExtension.cs
Normal file
31
HangfireExample.WebService/Extensions/HangfireExtension.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user