I have a windows service which uses Quartz
for scheduling the tasks. And I am trying to achieve the Dependency Injection
as by default the Quartz
doesn't support that with default Job Factory
. So I had to create a custom Job Factory
as follows.
var scheduler = await GetScheduler();
var serviceProvider = GetConfiguredServiceProvider();
scheduler.JobFactory = new CustomJobFactory(serviceProvider);
And below is my code for GetConfiguredServiceProvider()
.
private IServiceProvider GetConfiguredServiceProvider() {
var services = new ServiceCollection()
.AddScoped<IDailyJob, DailyJob>()
.AddScoped<IWeeklyJob, WeeklyJob>()
.AddScoped<IMonthlyJob, MonthlyJob>()
.AddScoped<IHelperService, HelperService>();
return services.BuildServiceProvider();
}
But on the line .AddScoped<IDailyJob, DailyJob>()
I am getting an error as
Severity Code Description Project File Line Suppression State Error CS1061 'ServiceCollection' does not contain a definition for 'AddScoped' and no accessible extension method 'AddScoped' accepting a first argument of type 'ServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Anyone else faced this same issue?