IOCJobFactory.cs 641 B

123456789101112131415161718192021222324252627
  1. using Quartz;
  2. using Quartz.Spi;
  3. namespace QuzrtzJob.Factory
  4. {
  5. public class IOCJobFactory : IJobFactory
  6. {
  7. private readonly IServiceProvider _serviceProvider;
  8. public IOCJobFactory(IServiceProvider serviceProvider)
  9. {
  10. _serviceProvider = serviceProvider;
  11. }
  12. public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
  13. {
  14. return _serviceProvider.GetService(bundle.JobDetail.JobType) as IJob;
  15. }
  16. public void ReturnJob(IJob job)
  17. {
  18. var disposable = job as IDisposable;
  19. disposable?.Dispose();
  20. }
  21. }
  22. }