Skip to content

Instantly share code, notes, and snippets.

@Guifgr
Created October 28, 2021 12:28
Show Gist options
  • Save Guifgr/ee4c084426829edddc1906f62e7c7f93 to your computer and use it in GitHub Desktop.
Save Guifgr/ee4c084426829edddc1906f62e7c7f93 to your computer and use it in GitHub Desktop.
Create Scope
private readonly IServiceProvider _serviceScopeFactory;
public GenericBackgroundTask(IServiceProvider serviceScopeFactory)
{
_serviceScopeFactory = serviceScopeFactory;
}
private async Task RunTaskAsync()
{
await Task.Delay(TimeSpan.FromMinutes(1));
try
{
using var scope = _serviceScopeFactory.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<THENEWSCOPE>();
await SOMEMETHODUSINGTHE(context);
}
catch (Exception e)
{
Console.Write(e.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment