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
}
}