Create a Quartz.NET Job with several constructor parameters

前端 未结 1 1447
余生分开走
余生分开走 2020-12-17 21:53

I have a job which needs to kick off some methods on another object. I\'d like to be able to pass these into the job in its constructor.

Looking around, it seems tha

相关标签:
1条回答
  • 2020-12-17 22:23

    You need to use JobFactory:

    internal sealed class IntegrationJobFactory : IJobFactory
    {
        private readonly IUnityContainer _container;
    
        public IntegrationJobFactory(IUnityContainer container)
        {
            _container = container;
        }
    
        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            var jobDetail = bundle.JobDetail;
    
            var job = (IJob)_container.Resolve(jobDetail.JobType);
            return job;
        }
    
        public void ReturnJob(IJob job)
        {
        }
    }
    

    And use it:

    var _scheduler = schedulerFactory.GetScheduler();
    var _scheduler.JobFactory = new IntegrationJobFactory(container);
    
    0 讨论(0)
提交回复
热议问题