コード例 #1
0
        /// <summary>
        /// Add job to underlying service collection.jobType shoud be implement `IJob`
        /// </summary>
        public static IServiceCollectionQuartzConfigurator AddJob(
            this IServiceCollectionQuartzConfigurator options,
            Type jobType,
            JobKey?jobKey = null,
            Action <IJobConfigurator>?configure = null)
        {
            if (!typeof(IJob).IsAssignableFrom(jobType))
            {
                ExceptionHelper.ThrowArgumentException("jobType must implement the IJob interface", nameof(jobType));
            }
            var c = new JobConfigurator();

            if (jobKey != null)
            {
                c.WithIdentity(jobKey);
            }

            var jobDetail = ConfigureAndBuildJobDetail(jobType, c, configure, hasCustomKey: out _);

            options.Services.Configure <QuartzOptions>(x =>
            {
                x.jobDetails.Add(jobDetail);
            });

            return(options);
        }
コード例 #2
0
        /// <summary>
        /// Add job to underlying service collection. This API maybe change!
        /// </summary>
        public static IServiceCollectionQuartzConfigurator AddJob <T>(
            this IServiceCollectionQuartzConfigurator options,
            JobKey?jobKey = null,
            Action <IJobConfigurator>?configure = null) where T : IJob
        {
            var c = new JobConfigurator();

            if (jobKey != null)
            {
                c.WithIdentity(jobKey);
            }

            var jobDetail = ConfigureAndBuildJobDetail <T>(c, configure);

            options.Services.Configure <QuartzOptions>(x =>
            {
                x.jobDetails.Add(jobDetail);
            });
            options.Services.TryAddTransient(jobDetail.JobType);

            return(options);
        }