开发者

How do I inject my repositories/interfaces in a class which requires an empty constructor?

开发者 https://www.devze.com 2023-01-12 10:22 出处:网络
In my controllers, I access my repositories like so: private readonly IProjectRepository projectRepository;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号