In order to do such a thing, I think you would need to serialize your object using
System.Text.Json and upload it in a separate storage system. That way, you could enqueue a message using Hangfire that reference the ID of the externally stored object.
That’s actually what I’ve done in this week. I built an abstraction over Hangfire that automatically serialize (using
System.Text.Json) any message to Azure Blob Storage. On the job execution side, the blob is downloaded and the corresponding object handler is getting called to continue the job execution.
Having your job parameters (or message) stored in another system offers actually several benefits:
- You decide how and where your message is serialized
- You’ll use less space in the Hangfire storage, making the whole system faster
- There will no longer be a limit to the size of the message
- There’s less chances that someone see PII from your users in the Hangfire dashboard
- If needed, inspecting/modifying the externally stored JSON object is easier than doing it in the Hangfire database