Home > front end >  How to Configure services in ASP.NET Core 6 MVC?
How to Configure services in ASP.NET Core 6 MVC?

Time:03-17

I am using .NET 6.0, and I am using Quartz.Net to schedule a event at a specific time.

I am using this: Tutorial

But in the end I need to configure in startup class inside the ConfigureServices method - like this:

// Add Quartz services
services.AddHostedService<QuartzHostedService>();
services.AddSingleton<IJobFactory, SingletonJobFactory>();
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();

// Add our job
services.AddSingleton<RemindersJob>();
services.AddSingleton(new JobSchedule(
    jobType: typeof(RemindersJob),
    cronExpression: "0 0/5 * 1/1 * ? *")); // run every 5 min

But the startup class is not there in my project, so how should I configure this?

CodePudding user response:

The tutorial you are looking at is probably .NET Core 5. In .NET 6 you need to configure in Program.cs and change this:

services.AddScoped<IJobFactory, SingletonJobFactory>();
services.AddScoped<ISchedulerFactory, StdSchedulerFactory>();

insted of this:

services.AddSingleton<IJobFactory, SingletonJobFactory>();
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();

CodePudding user response:

You need to configure in Program.cs

  • Related