Creating a Quartz.NET Job with Several Designer Parameters

I have a job that should run some methods on another object. I would like to be able to pass them to work in my constructor.

Looking back, it seems that the only way to achieve this is to use one of the IoC frameworks. Although this method will be a solution for me in the future, right now I need a vanilla solution that does not require any IoC.

I know JobDataMap, but Best Practice Recommendations advises against this because of serialization. The object is multi-threaded and statefull, so serialization will be code suicide anyway.

How to create a task like the one below:

public class MyJob : IJob
{
    private readonly IFoo _foo;

        public StopMonitoring(IFoo foo)
        {
            _foo = foo;
        }

        public void Execute(IJobExecutionContext context)
        {
            foo.GetCurrentState();
        }
    }
}
+3
source share
1

JobFactory:

internal sealed class IntegrationJobFactory : IJobFactory
{
    private readonly IUnityContainer _container;

    public IntegrationJobFactory(IUnityContainer container)
    {
        _container = container;
    }

    public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
    {
        var jobDetail = bundle.JobDetail;

        var job = (IJob)_container.Resolve(jobDetail.JobType);
        return job;
    }

    public void ReturnJob(IJob job)
    {
    }
}

:

var _scheduler = schedulerFactory.GetScheduler();
var _scheduler.JobFactory = new IntegrationJobFactory(container);
+6

All Articles