简体   繁体   中英

How to Configure services in ASP.NET Core 6 MVC?

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?

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>();

You need to configure in Program.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM