4

Hy guys, I'm getting really confused so please help me out. I'm having a problem regarding the creation of an instance using Unity. The instance i want to create is of type Client, and i want to create it inside the Job constructor, but it keeps giving me null reference error. In other cases let's say inside a controller the resolving works just fine , but inside this scheduled job it doesn't work anymore.

The creation of the scheduler is made inside Global.asax


    private void SchedulerStart()
    {
    ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
              IScheduler scheduler = schedulerFactory.GetScheduler();
              scheduler.Start();
              IJobDetail job = JobBuilder.Create().WithIdentity("CheckForCompletedJobs").Build();
                ITrigger trigger = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInHours(24)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(4, 03))
                  )
                .Build();
                scheduler.ScheduleJob(job, trigger);
    }



     public class CheckForCompletedJobs : IJob
        {
          private readonly IPhotoEventRepository _photoEventRepository;
          public CheckForCompletedJobs()
          {  
              _clientRepository = DependencyResolver.Current.GetService();
          }
          public void Execute(IJobExecutionContext context)
          {
              //some action with the clientRepository 
          }
        }

Jehof
  • 34,674
  • 10
  • 123
  • 155
  • Can you also post your quartz.net config file? – yorah Oct 25 '12 at 09:00
  • The job class posted won't compile (_clientRepository is mentioned when only _photoEventRepository is declared). Where is your null reference? DependencyResolve.Current? – Josh Gallagher Oct 26 '12 at 22:09

0 Answers0