Created
October 4, 2013 09:01
-
-
Save metavige/6823063 to your computer and use it in GitHub Desktop.
Quartz.Net + Ninject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; using Microsoft.Practices.ServiceLocation; using Quartz; using Quartz.Spi; namespace Nebula.JobAgent.Common { public class JobFactory : IJobFactory { public Quartz.IJob NewJob(TriggerFiredBundle bundle, Quartz.IScheduler scheduler) { try { var jobDetail = bundle.JobDetail; var jobType = jobDetail.JobType; return (IJob)ServiceLocator.Current.GetInstance(jobType); } catch (Exception e) { var se = new SchedulerException("Problem instantiating class", e); throw se; } } public void ReturnJob(IJob job) { // TODO??? } } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bind<ISchedulerFactory>().To<StdSchedulerFactory>().InSingletonScope(); Bind<IJobFactory>().To<JobFactory>().InSingletonScope(); Bind<IScheduler>().ToMethod((c) => { var scheduleFactory = (ISchedulerFactory)c.Kernel.GetService(typeof(ISchedulerFactory)); var jobFactory = (IJobFactory)c.Kernel.GetService(typeof(IJobFactory)); IScheduler scheduler = scheduleFactory.GetScheduler(); scheduler.JobFactory = jobFactory; return scheduler; }).InSingletonScope(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment