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??