HangfireIO / HangfireIO/Hangfire

Asp.Net Core Singleton being activated multiple times

Open
#1,491 4 comments 0 reactions 0 assignees View on GitHub
t: question
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

I have a singleton registered in my startup.cs like so `services.AddSingleton();`. I also am adding hangfire and the service like so `services.AddHangfire(...)` and `services.AddHangfireServer(...)`. I know from looking at `HangfireServiceCollectionExtensions` that it should add the `AspNetCoreJobActivator` without me doing any extra work. That said, if I put a break point in the constructor of `TriggerWarmup` it gets hit once on app startup and then again when a job that targets it gets registered. Note, if i run that job multiple times after that initial run, the constructor doesn't get called again... so it seems like its kinda getting registered as a singleton but not really. Any thoughts?

Contributor guide

Open the contributing guide

Research direction

Start with startup.cs and HangfireServiceCollectionExtensions, then trace how AspNetCoreJobActivator resolves TriggerWarmup during job registration and execution. Reproduce the constructor behavior described in the issue and determine whether the activation differs between application startup and the first targeted job. Done means the cause is identified and the singleton behavior is either corrected or clearly documented.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.