Created
October 28, 2021 12:28
-
-
Save Guifgr/ee4c084426829edddc1906f62e7c7f93 to your computer and use it in GitHub Desktop.
Create Scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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