views:

53

answers:

1

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 something 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!

+1  A: 

Use the Quartz.Net integration facility. It will let you treat quartz jobs just like any other Windsor service.

Mauricio Scheffer
Sweet! You might want to mention that quartz_jobs.xml needs to be in the dev server folder and not the root project folder in a .NET app.
KieselguhrKid
@KieselguhrKid: I did not understand your comment... what's the "dev server folder"? I **do** have my quartz_jobs.xml in the project root directory.
Mauricio Scheffer
At least on my system, when it is running in the context of a web application, it looks for quartz_jobs file in the folder where the IIS server executes, not the project folder. So if you're running in a dev environment it'll look for the quartz_jobs where the cassini server executes. If you're running a console app, like in your sample, this is the same as the project folder. Does that make any sense?
chum of chance
@chum of chance: use ~/quartz_jobs.xml to read it from the app root
Mauricio Scheffer

related questions