這是我的代碼,它不工作,因爲顯然,IJobDetails
需要與作業生成器一起創建。有什麼辦法用構造函數中給出的外部依賴來創建Job?使用DI與石英
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);
演員是壞的,但是這是我想要做的(BbProcessor
是給構造器的依賴類,做的工作,我想這樣做)只是例子。
public class BbProcessor : IJob
{
private readonly Repository _repository;
public BbProcessor(Repository Repository)
{
_repository = Repository;
}
}
,你能否告訴我們代碼到BbProcessor? –
'public class BbProcessor:IJob { private private readonly Repository _repository;公共BbProcessor(版本庫) { }' –
我想你也需要一個無參數的構造函數。請參閱下面我編輯的答案。 –