Using One Hangfire Server in several projects

I am using Hanfire in one of my project. I would like to add jobs to this hangfire instance from another project (on the same solution). I can’t add reference to first project. The only one way to do this is to separate hangfire to another project?

I am also looking for a solution to this issue.

I have asked on Stack Excahgne

@Zapnologica What did you mean “How would I go about implementing hangfire”?

What do you expect from Services layer? Could you please be more specific and I’ll try helping you.

In my company I’m using a Windows Service as Server and MVC as Dashboard. Both looks to the same database.

@gandarez
Thank you for your response.

When I say Implement, I am assuming that the standard install nuget approach wont work for me? I am going to have to implement the configuration to use the same hangfire instance in two projects. My thoughts are that im gonna have to install the nuget package in the services layer (Class Application) project, and then create a shared config or initialization class for my hangfire,

Could you also maybe clarify what runs the tasks, Will they actually run from within the IIS pool? And In my case can I not create a server which all my projects user to run the tasks?

My services layer will mainly be doing the following:

Push notifications:
Emails
Sms

Payments from x to y using gateway.

Database cleanup and inserting on a recurring task.

My windows service basically runs the hangfire server

_server = new BackgroundJobServer(new BackgroundJobServerOptions { Queues = queues.ToArray() });

My web mvc project is the Hangfire Dashboard native implementation.

I’m still trying to figure out what do you want to achieve. Both of my projects have referenced the same Hangfire.Core library and that’s it.

So then which of your projects generate the tasks? I want to take your scenario and add a 3rd element. A Web api. Which generates the tasks to run. Then the service will run them. And the mvc project will be the dashboard.

Did you mean which project add recurring or fire and forget tasks? If it’s your question, my answer is: Windows Service. It adds new jobs and run Hangfire server. But I can’t see any obstacles using a third element to add jobs (web api). What you need is to have a shared folder with your binaries. When Hangfire.Core gets these libraries it needs to get the type and run it.

What will stop both the API and the Windows Service From running the tasks? They are both going to connect to the same database. But somewhere I have to tell the web api, That It must NOT run tasks, Only submit tasks.

Maybe your web api may not start BackgroundJobServer just set globals to connect to hangfire database?