Let’s say I have a class with 200 functions and procedures. Only 3 of them used by BackgroundJob.Enqueue function. Rest is some bunch of functions for other purposes. I can separate these 3 into new class.
What I want to know is should I do that ? Or can I continue to use my big class (but actually only 3 of them) without any concern ? Is there any performance issues, storage size issues ?
Hangfire only need to serialize the typename, method name and your arguments.
It doesn’t matter how many methods/members the type contains, Hangfire never serializes any of that. Main concern is to make your type and number of arguments to the method as small as possible since that is what is going to be serialized.
Ie. if you have a lot of input-data to your method, its better to store that as a record somewhere in a database and only pass a id to your method which then knows how to load up your argument data.
@burningice is correct that none of it matters from a hangfire perspective, but to answer your question of what should you do. From an architectural perspective if the only purpose these 3 functions serve is to execute specific fire and forget functionality, I would want them separated out and have the class named and namespaced appropriately to signal exactly what it does. Again though this is more of an architectural question than a performance question.
Giving specific architectural advise with so little context is always hard, but i can say for my own point of view is that i always encapsulate each task i want Hangfire to handle into a class which has a single Execute-method taking some simple arguments. The class is registered in a IoC container so Hangfire can instantiate it and inject necessary dependencies and i then register the task in Hangfire like this