HangFire could work with 2 constructors?

Tags: #<Tag:0x00007efd22d0e668> #<Tag:0x00007efd22d0e410>

I have this class “TaskScheduleService” with 2 constructor, its created like this because for some methods I only need some parameters

public TaskScheduleService(IServiceScopeFactory serviceScopeFactory, IEmailConfiguration emailConfiguration)
{
m_serviceScopeFactory = serviceScopeFactory;
m_emailConfiguration = emailConfiguration;
}

public TaskScheduleService(IServiceScopeFactory serviceScopeFactory, IEmailConfiguration emailConfiguration,
ShipStationServiceFactory shipStationServiceFactory, SimpleServiceFactory simpleServiceFactory,
IHubContext<ProgressHub, IProgressClient> hubContext)
{
m_serviceScopeFactory = serviceScopeFactory;
m_emailConfiguration = emailConfiguration;
m_shipStationServiceFactory = shipStationServiceFactory;
m_simpleServiceFactory = simpleServiceFactory;
m_hubContext = hubContext;
}

then I have my recurringJob

TaskScheduleService taskScheduleService = new TaskScheduleService(m_serviceScopeFactory, m_emailConfiguration, m_shipStationServiceFactory, m_simpleServiceFactory, m_hubContext);
RecurringJob.AddOrUpdate(() => taskScheduleService.TaskSyncShipStation(), cronExpression, TimeZoneInfo.Utc);

where TaskSyncShipStation() is a method in the class “TaskScheduleService”

The problem it looks when the Job is fire, always take the first constructor, because the other parameters are set with null.

There is a way to specify which constructor needs to take the hangfire??

Are you ising an ioc container? Cause if you do i would imagine it’s up to that one how to choose. Most containers would choose the constructor with the most parameters it knows how to fill. AFAIK.
If you don’t use a container, maybe you should…? :nerd_face: