How to pass method in Recurring Job in Hangfire?

beginer
beginer
Participant
1478 Points
49 Posts

I'm try to call method as:

RecurringJob.AddOrUpdate<IAccount>("RecurringJob.UpdateUserActivity", x => x.MigrateUserActivityUpdate(), Cron.Daily(10, 30));

Where

public interface IAccount
{
  void MigrateUserActivityUpdate();
}

But it's throwing error:

System.MissingMethodException: Cannot create an instance of an interface.

 

Views: 198
Total Answered: 1
Total Marked As Answer: 0
Posted On: 04-May-2024 00:57

Share:   fb twitter linkedin
Answers
Brian
Brian
Moderator
2342 Points
13 Posts
         

Hangfire uses the JobActivator class to instantiate the target types before invoking instance methods. You can override its behavior to perform more complex logic on a type instantiation.

Here is link: https://docs.hangfire.io/en/latest/background-methods/using-ioc-containers.html

 

Posted On: 07-May-2024 22:13
 Log In to Chat