HangfireIO / HangfireIO/Hangfire
Dependency Injection - Singleton Services
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Hello!
I've wired up Hangfire into my Asp.Net Core app and am using Asp.Net's own Dependency Injection mechanism (configuring Hangfire with a custom ServiceProvider JobActivator).
Dependencies get resolved correctly and jobs are activated successfully, however, it seems that Singleton services are created twice. Perhaps once in the Application context, and a second time in Hangfire's execution context. In effect, Singleton services are now suddenly ... Dualton? :)
Is Hangfire able to cross-over and use an active instance of a service in the application context without relying on Static methods? If so, can you please elaborate on the correct way to achieve this? I wonder whether I've done something funky with passing my ServiceProvider to Hangfire, or there's some fundamental reason why Hangfire won't cross-over and use instances already active in the application context.
Thanks,
Arash
Contributor guide
Research direction
Start with the custom ServiceProvider JobActivator and ASP.NET Core dependency-injection setup described in the issue, then reproduce singleton resolution from both the application and a Hangfire job. Done means establishing whether two instances are expected, identifying the lifetime boundary if not, and recording the supported integration behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100