Hi guys. I have one question. I need RecurringJob that will do something every hour. Lets say for example send an email. Every tutorial is doing same thing, something like this:
And they put that line of code in the Startup.cs/Prgoram.cs. But first of all, I guess we should not call it from Program.cs? But where should we place this line of code, since I dont want use Console.WriteLine but some methode from my services. For example:
You can put it in Program.cs. To use RecurringJob the Hangfire setup/initialization code has to have already run. In your example there is message. Where is message coming from? Does it send the same email every hour?
Technically yes but no. It is recurring. Anything you pass would be hard coded. If you have to determine something I would create a class to perform the logic.
public class SendEmailJob
{
private readonly IEmailService _emailService;
public SendEmailJob(IEmailService emailService)
{
_emailService = emailService;
}
public void Send()
{
// Logic here to determine what to email.
_emailService.Send(...);
}
}