Skip to content

Working with Quartz.Net #2

@mtugnoli

Description

@mtugnoli

Hi,
I would like to to use a service with a scheduled job
I tried this, but this error occour ..
: 'The request lifetime scope cannot be created because the HttpContext is not available.'

How I have to configure it ?

public class EmailJobScheduler
{
	public void Start()
	{
		IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
		IJobDetail job = JobBuilder.Create<MyJob>().Build();

		ITrigger trigger = TriggerBuilder.Create()
			.WithSimpleSchedule(t =>
				t.WithIntervalInSeconds(60)
				.RepeatForever()
				)
			.Build();

		scheduler.ScheduleJob(job, trigger);
		scheduler.Start();
	}
}

public class MyJob : IJob
{
	public async void Execute(IJobExecutionContext context)
	{
		// How can call the service ?
		var projectService = DependencyResolver.Current.GetService<IProjectService>(); // ERRROR

	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions