This is my code and it is not working, because apparently, IJobDetails
needs to be created with job builder. Is there any way to create Job with external dependencies given in constructor?
var container = new UnityContainer();
container.RegisterType<BbProcessor, BbProcessor>();
IJobDetail jobProcessor = container.Resolve<BbProcessor>() as IJobDetail;
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
ITrigger trigger = TriggerBuilder.Create()
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
sched.ScheduleJob(jobProcessor , trigger);
The cast is bad, but this is just example what I'm trying to do (BbProcessor
is the class with dependencies given to constructor and doing work I want to do).
public class BbProcessor : IJob
{
private readonly Repository _repository;
public BbProcessor(Repository Repository)
{
_repository = Repository;
}
}