Hello!
I need to start job, which will start some processing.
I have class TaskSSN and the method Process in it. TaskSSN class have constructor with two parameters.
public class TaskSSN
{
private string fileName;
private string fileContent;
public TaskSSN(string fileName, string fileContent)
{
this.fileName = fileName;
this.fileContent = fileContent;
}
public void Process()
{
//some actions...
}
}
Then I create object instanse and call Process method:
public void SomeMethod (LoadArg arg)
{
TaskSSN task = new TaskSSN(arg.FileName, arg.FileContent);
BackgroundJob.Enqueue(() => task.Process());
}
I understand that Hangfire uses default constructor and doesn’t have access to the object instance. In this issue Hangfire needs parameterless constructor it is said about dependency injection container and JobActivator. Sorry, but I’m new in dependency injection and don’t understand how to use DI and JobActivator in this case .
Can you tell me please (using my code, if it possible), how can I fix problem with parameterized constructor?
If you can refactor your code and move the arguments into your Process method signature then you can avoid a parameterized constructor and pass arguments in like this: