Reputation: 22506
I use Quartz.NET this way:
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = schedulerFactory.GetScheduler();
scheduler.Start();
IJobDetail clearCacheJob = JobBuilder.Create<ClearCacheJob>()
.WithIdentity("ClearCacheJob", "CacheGroup")
.Build();
scheduler.ScheduleJob(clearCacheJob, buildTrigger(cacheCronExpr));
ClearCacheJob
is a class that implements IJob
It works, but now I want to add a property in the ClearCacheJob
class. Something like:
public class ClearCacheJob : IJob
{
public ISomeService {get; set;}
public void Execute(IJobExecutionContext context)
{
//do stuff
}
}
How can I set SomeService
?
Upvotes: 2
Views: 1573
Reputation: 1476
I know I am late to the party, but I have also written a blog post with a full working example using Ninject. The blog post can be found here:
http://codein60seconds.blogspot.com/2015/08/quartz-with-ninject-dependency-injection.html
The source code for the example can be found here:
https://github.com/cknightdevelopment/CodeIn60Seconds/tree/master/DotNet/QuartzWithNinject
Thanks.
EDIT
Blog post is now here:
http://knightcodes.com/.net/2016/08/15/dependency-injection-for-quartz-net.html
And the source code here:
https://github.com/cknightdevelopment/KnightCodesExamples/tree/master/DotNet/Quartz.Ninject
And the YouTube video here:
https://www.youtube.com/watch?v=RlW4vUsoxEY
Upvotes: 0
Reputation: 6789
Stuart's comment is spot on. You'll need to implement your own job factory. I've written a blog post describing the process here: http://jayvilalta.com/blog//2012/07/23/creating-a-custom-quartz-net-jobfactory/
As far as DI containers goes, Castle is also supported. Do a search on NuGet for Quartz.Net and scroll through the list. You'll see castle, structuremap, ninject, autofac, etc.
Upvotes: 3