Dependencies of Hangfire client code at Hangfire Server while executing the job fetched from db


#1

I am using Hangfire to trigger a task daily. I have made two solutions. One for Hangfire Client and another for Hangfire Server. The task is to make a call to another API. When I run this Hangfire client, it is adding the job to MongoDB Successfully.

But when Server solution is ran, It is throwing an error : Could not load file or assembly ‘schedulingclient.Web, Culture=neutral, PublicKeyToken=93cadf9107ebec2e’. The system cannot find the file specified.

scheduling client is the API and also works as Hangfire client. This dependencies are throwing errors when Server is trying to execute the parsed job. The job which is in Client has no ‘usings’ related to the other files in solution. though I am facing this issue. I have tried referencing the client’s .dll in Server’s solution. It is working but this is not the ideal way as client is an API not a library. Please let me know if there are any mistakes and any suggestions, Welcome.


#2

When you schedule a job, the job object is serialized. To dequeue that job, it needs to be deserialized.
What you can do, is to use interfaces instead of classes for your jobs. E.g.

public class MyJob : IMyJob {
   public void DoThatThing()
}

No you can put the interface in a common assembly and the implementation in the server assembly. The client don’t need to know the actual implementation - it only knows there is a IMyJob that can DoThatThing(), so it schedules that thing to be done. The server side will dequeue the job and see that it is a IMyJob thing. It will then look for a suitable implementation for IMyJob and find the MyJob class.

Take a look at the documentation for using ioc containers to help hangfire find the implementation of the interface.