Unity MVC3无法解析Quartz.net作业构造函数中的对象

时间:2012-10-25 02:12:47

标签: asp.net-mvc-3 unity-container quartz.net quartz.net-2.0

嗨伙计们,    我真的很困惑所以请帮帮我。我在使用Unity创建实例方面遇到了问题。我想创建的实例是Client类型,我想在Job构造函数中创建它,但它一直给我空引用错误。在其他情况下,让我们说在控制器内部解析工作正常,但在此预定作业中它不再起作用。

调度程序的创建在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 
          }
        }

0 个答案:

没有答案