-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPumpingBackgroundServiceOrgScoped.cs
More file actions
30 lines (25 loc) · 1.12 KB
/
PumpingBackgroundServiceOrgScoped.cs
File metadata and controls
30 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Auth0Net.DependencyInjection.Organizations;
using Sample.ConsoleApp.Services;
#pragma warning disable AUTH0_EXPERIMENTAL
namespace Sample.ConsoleApp;
// Not a realistic example, just using it to hit our API.
public class PumpingBackgroundServiceOrgScoped : BackgroundService
{
private readonly OrganizationScopeFactory<UsersService> _scopeFactory;
private readonly ILogger<PumpingBackgroundService> _logger;
public PumpingBackgroundServiceOrgScoped(OrganizationScopeFactory<UsersService> scopeFactory, ILogger<PumpingBackgroundService> logger)
{
_scopeFactory = scopeFactory;
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using var scopedClient = _scopeFactory.CreateScope("org_12345");
while (!stoppingToken.IsCancellationRequested)
{
var userHttpClient = await scopedClient.Client.GetUsersAsync(stoppingToken);
_logger.LogInformation("HttpClient got user's email: {email}", userHttpClient?.First().Email);
await Task.Delay(5000, stoppingToken);
}
}
}