From 175b6a416e813e963e88435ef415a719b129099b Mon Sep 17 00:00:00 2001 From: suravi999 Date: Thu, 19 Mar 2020 20:17:28 +0530 Subject: [PATCH 1/2] Update Background-Jobs-Hangfire.md Add Hangfire Configuration --- docs/en/Background-Jobs-Hangfire.md | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/en/Background-Jobs-Hangfire.md b/docs/en/Background-Jobs-Hangfire.md index 588fcace9e..ebaf8271b8 100644 --- a/docs/en/Background-Jobs-Hangfire.md +++ b/docs/en/Background-Jobs-Hangfire.md @@ -39,5 +39,50 @@ public class YourModule : AbpModule ```` ## Configuration +You can install any storage for Hangfire. The most common one is SQL Server (see the [Hangfire.SqlServer](https://www.nuget.org/packages/Hangfire.SqlServer) NuGet package). -TODO... \ No newline at end of file +After you have installed these NuGet packages, you need to configure your project to use Hangfire. + +1.First, we change the `HttpApiHostModule` class to add Hangfire configuration of the storage and connection string in the `ConfigureServices` method: + + +````csharp + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + var hostingEnvironment = context.Services.GetHostingEnvironment(); + + //... other configarations + + ConfigureHangfire(context, configuration); + } + + private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration) + { + context.Services.AddHangfire(config => + { + config.UsePostgreSqlStorage(configuration.GetConnectionString("Default")); + }); + } +```` + +2. We need to add `UseHangfireServer` call in the Configure method in `Startup` class + +If you want to use hangfire's dashboard, you can add it, too: by `UseHangfireDashboard` + +````csharp + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddApplication(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + app.InitializeApplication(); + app.UseHangfireServer(); + app.UseHangfireDashboard(); + } + } +```` From 0e70f9e9b6fc8fc19a8e88a4eaba8eccf9180e40 Mon Sep 17 00:00:00 2001 From: suravi999 Date: Fri, 20 Mar 2020 12:33:59 +0530 Subject: [PATCH 2/2] Update Background-Jobs-Hangfire.md Add requested changes in documentation. --- docs/en/Background-Jobs-Hangfire.md | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/en/Background-Jobs-Hangfire.md b/docs/en/Background-Jobs-Hangfire.md index ebaf8271b8..622558ac68 100644 --- a/docs/en/Background-Jobs-Hangfire.md +++ b/docs/en/Background-Jobs-Hangfire.md @@ -43,7 +43,7 @@ You can install any storage for Hangfire. The most common one is SQL Server (see After you have installed these NuGet packages, you need to configure your project to use Hangfire. -1.First, we change the `HttpApiHostModule` class to add Hangfire configuration of the storage and connection string in the `ConfigureServices` method: +1.First, we change the `Module` class (example: `HttpApiHostModule`) to add Hangfire configuration of the storage and connection string in the `ConfigureServices` method: ````csharp @@ -61,28 +61,24 @@ After you have installed these NuGet packages, you need to configure your projec { context.Services.AddHangfire(config => { - config.UsePostgreSqlStorage(configuration.GetConnectionString("Default")); + config.UseSqlServerStorage(configuration.GetConnectionString("Default")); }); } ```` -2. We need to add `UseHangfireServer` call in the Configure method in `Startup` class +2. We need to add `UseHangfireServer` call in the `OnApplicationInitialization` method in `Module` class If you want to use hangfire's dashboard, you can add it, too: by `UseHangfireDashboard` ````csharp - public class Startup + public override void OnApplicationInitialization(ApplicationInitializationContext context) { - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - app.UseHangfireServer(); - app.UseHangfireDashboard(); - } + var app = context.GetApplicationBuilder(); + + // ... others + + app.UseHangfireServer(); + app.UseHangfireDashboard(); + } ````