How do I inject my repositories/interfaces in a class which requires an empty constructor?
In my controllers, I access my repositories like so:
private readonly IProjectRepository projectRepository;
public ProjectsController(IProjectRepository projectRepository) {
Check.Require(projectRepository != null, "projectRepository may not be null");
this.projectRepository = projectRepository;
}
[Transaction]
public ActionResult Index() {
var projects = projectRepository.GetAll();
return View(projects);
}
This gives me access to manipulating and persisting objects to my database. I'm trying to use Quartz.Net, but the Quartz jobs take an empty constructor, like this:
private readonly IProjectRepository projectRepository;
public QuartzJob() {}
public void Execute(JobExecutionContext context)
{
var projects = projectRepository.GetAll();
}
That will result in a null object reference because I haven't initiated it. How do I get around this? I feel as if this has 开发者_StackOverflowsomething to do with castle windsor, but I'm still new to this and don't know how to proceed. I can't be the first person to use a Sharp project with Quartz.Net, any help would be appreciated. Thanks!
Use the Quartz.Net integration facility. It will let you treat quartz jobs just like any other Windsor service.
精彩评论