From 17f345c5a797ae12b5e501e8f69255043ff76cb8 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 1 Dec 2022 11:15:36 +0800 Subject: [PATCH] Update Hangfire document --- docs/en/Background-Workers-Hangfire.md | 21 +++++++-------------- docs/zh-Hans/Background-Workers-Hangfire.md | 21 +++++++-------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/docs/en/Background-Workers-Hangfire.md b/docs/en/Background-Workers-Hangfire.md index b076cf0395..4706261849 100644 --- a/docs/en/Background-Workers-Hangfire.md +++ b/docs/en/Background-Workers-Hangfire.md @@ -53,7 +53,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase CronExpression = Cron.Daily(); } - public override Task DoWorkAsync() + public override Task DoWorkAsync(CancellationToken cancellationToken = default) { Logger.LogInformation("Executed MyLogWorker..!"); return Task.CompletedTask; @@ -68,14 +68,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase ### UnitOfWork -For use with `UnitOfWorkAttribute`, you need to define an interface for worker: - ```csharp -public interface IMyLogWorker : IHangfireBackgroundWorker -{ -} - -[ExposeServices(typeof(IMyLogWorker))] public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker { public MyLogWorker() @@ -85,10 +78,13 @@ public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker } [UnitOfWork] - public override Task DoWorkAsync() + public override Task DoWorkAsync(CancellationToken cancellationToken = default) { - Logger.LogInformation("Executed MyLogWorker..!"); - return Task.CompletedTask; + using (var uow = LazyServiceProvider.LazyGetRequiredService().Begin()) + { + Logger.LogInformation("Executed MyLogWorker..!"); + return Task.CompletedTask; + } } } ``` @@ -105,9 +101,6 @@ public class MyModule : AbpModule ApplicationInitializationContext context) { await context.AddBackgroundWorkerAsync(); - - //If the interface is defined - //await context.AddBackgroundWorkerAsync(); } } ```` diff --git a/docs/zh-Hans/Background-Workers-Hangfire.md b/docs/zh-Hans/Background-Workers-Hangfire.md index b02a793d3f..1ff88f7620 100644 --- a/docs/zh-Hans/Background-Workers-Hangfire.md +++ b/docs/zh-Hans/Background-Workers-Hangfire.md @@ -54,7 +54,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase CronExpression = Cron.Daily(); } - public override Task DoWorkAsync() + public override Task DoWorkAsync(CancellationToken cancellationToken = default) { Logger.LogInformation("Executed MyLogWorker..!"); return Task.CompletedTask; @@ -69,14 +69,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase ### UnitOfWork -使用 `UnitOfWorkAttribute` 你需要为工作者定义一个接口: - ```csharp -public interface IMyLogWorker : IHangfireBackgroundWorker -{ -} - -[ExposeServices(typeof(IMyLogWorker))] public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker { public MyLogWorker() @@ -86,10 +79,13 @@ public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker } [UnitOfWork] - public override Task DoWorkAsync() + public override Task DoWorkAsync(CancellationToken cancellationToken = default) { - Logger.LogInformation("Executed MyLogWorker..!"); - return Task.CompletedTask; + using (var uow = LazyServiceProvider.LazyGetRequiredService().Begin()) + { + Logger.LogInformation("Executed MyLogWorker..!"); + return Task.CompletedTask; + } } } ``` @@ -106,9 +102,6 @@ public class MyModule : AbpModule ApplicationInitializationContext context) { await context.AddBackgroundWorkerAsync(); - - //如果定义了接口 - //await context.AddBackgroundWorkerAsync(); } } ````