1
1
using Microsoft . Extensions . DependencyInjection ;
2
2
using Microsoft . Extensions . Hosting ;
3
+ using Quartz ;
3
4
using Quartz . Impl ;
4
5
using Quartz . Spi ;
5
6
using System ;
@@ -15,7 +16,37 @@ public static class HostBuilderExtensions
15
16
/// <param name="builder">The NET Core HostBuilder</param>
16
17
/// <param name="configure">A function that will receive the HostBuilderContext and the StdSchedulerFactory config collection</param>
17
18
/// <returns>The HostBuilder itselft</returns>
18
- public static IHostBuilder UseQuartz ( this IHostBuilder builder , Action < HostBuilderContext , QuartzConfigCollection > configure = null )
19
+ public static IHostBuilder UseQuartz (
20
+ this IHostBuilder builder ,
21
+ Action < HostBuilderContext , QuartzConfigCollection > configure = null )
22
+ {
23
+ return UseQuartz ( builder , configure ) ;
24
+ }
25
+
26
+ /// <summary>
27
+ /// Registers the Scheduler, JobFactory, QuartzConfigCollection and the QuartzHostedService on the service collection
28
+ /// </summary>
29
+ /// <param name="builder">The NET Core HostBuilder</param>
30
+ /// <param name="configure">A function that will receive the HostBuilderContext, the ServiceProvider and the IScheduler instance</param>
31
+ /// <returns>The HostBuilder itselft</returns>
32
+ public static IHostBuilder UseQuartz (
33
+ this IHostBuilder builder ,
34
+ Action < HostBuilderContext , IServiceProvider , IScheduler > configure )
35
+ {
36
+ return UseQuartz ( builder , null , configure ) ;
37
+ }
38
+
39
+ /// <summary>
40
+ /// Registers the Scheduler, JobFactory, QuartzConfigCollection and the QuartzHostedService on the service collection
41
+ /// </summary>
42
+ /// <param name="builder">The NET Core HostBuilder</param>
43
+ /// <param name="configureFactory">A function that will receive the HostBuilderContext and the StdSchedulerFactory config collection</param>
44
+ /// <param name="configureScheduler">A function that will receive the HostBuilderContext, the ServiceProvider and the IScheduler instance</param>
45
+ /// <returns>The HostBuilder itselft</returns>
46
+ public static IHostBuilder UseQuartz (
47
+ this IHostBuilder builder ,
48
+ Action < HostBuilderContext , QuartzConfigCollection > configureFactory = null ,
49
+ Action < HostBuilderContext , IServiceProvider , IScheduler > configureScheduler = null )
19
50
{
20
51
builder . ConfigureServices ( ( context , collection ) =>
21
52
{
@@ -26,11 +57,11 @@ public static IHostBuilder UseQuartz(this IHostBuilder builder, Action<HostBuild
26
57
collection . AddSingleton < IJobFactory , JobFactory > ( ) ;
27
58
collection . AddSingleton ( ( provider ) =>
28
59
{
29
- configure ? . Invoke ( context , config ) ;
60
+ configureFactory ? . Invoke ( context , config ) ;
30
61
var factory = new StdSchedulerFactory ( config ) ;
31
-
32
62
var scheduler = factory . GetScheduler ( ) . Result ;
33
63
scheduler . JobFactory = provider . GetRequiredService < IJobFactory > ( ) ;
64
+ configureScheduler ? . Invoke ( context , provider , scheduler ) ;
34
65
return scheduler ;
35
66
} ) ;
36
67
} ) ;
0 commit comments