We have a .net 6 worker service.
Within this worker there is an injected scoped dbcontext as well as an injected service that uses this context.
The service looks something like this:
Publc ServiceConstructor(Mycontext context)
{
_dbContext = context; <---- scoped injected db
}
Public async Task DoWork()
{
//Do Work
}
Startup has:
services.AddScoped<Mycontext>();
services.AddScoped<Myservice>()
And in my worker's ExcecuteAsync()
using(var scope = _serviceProvider.CreateScope()){
//get service here using getrequiredservice
}
The problem I am facing is that I need to schedule doWork using cron. But also keeping in mind that a second and 3rd service will be added and 2 of them will run at the same time and the 3rd on a different time. But all 3 should be easy to set a new time.
Is there an easy way to schedule all 3 service functions individually?
All 3 will use the same database.