How to capture the creator of a job?

Hello, @yinkinkwok and thanks for the good words!

Coz i am thinking to implement a mechanism to notify the job creator upon their job’s completion.

Just include the notification into the job itself. You can look at HangFire.Highlighter sample.

Static method:

public void TargetMethod(int entityId)
{
    // Processing
    JobCreator.Notify("completed", entityId);
}

Instance method:

public void TargetMethod(int entityId)
{
    // Processing
    var creator = new JobCreator();
    creator.Notify("completed", entityId);
}

Constructing JobCreator in the ctor:

public class MyService
{
    private JobCreator _jobCreator = new JobCreator();

    public void TargetMethod(int entityId)
    {
        // Processing
        _jobCreator.Notify("completed", entityId);
    }
}

Passing a dependency through constructor this requires integration with IoC container (see here), because HangFire should create an instance of the MyService class before calling the target method.

public class MyService
{
    private JobCreator _jobCreator;

    public MyService(JobCreator jobCreator)
    {
        _jobCreator = jobCreator;
    }

    public void TargetMethod(int entityId)
    {
        // Processing
        _jobCreator.Notify("completed", entityId);
    }
}