Skip to content

Instantly share code, notes, and snippets.

@metavige
Created October 4, 2013 09:01
Show Gist options
  • Save metavige/6823063 to your computer and use it in GitHub Desktop.
Save metavige/6823063 to your computer and use it in GitHub Desktop.
Quartz.Net + Ninject
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??? } } }
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