Code
·
41 lines
·
824 bytes
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
31
32
33
34
35
36
37
38
39
40
41namespace SessionScopedTest.Services;
public class ExampleService(ILoggerFactory loggerFactory) : IHostedService
{
private readonly ILogger Logger = loggerFactory.CreateLogger<ExampleService>();
private string name = "unknown";
public async Task<bool> SetNameAsync(string Name)
{
this.name = Name;
Logger.LogInformation("SetNameAsync {Name}", Name);
await Task.Delay(100);
return true;
}
public async Task<string> GetNameAsync()
{
Logger.LogInformation("GetNameAsync {name}", name);
await Task.Delay(100);
return name;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
Logger.LogWarning("StartAsync");
await Task.Delay(100);
}
public async Task StopAsync(CancellationToken cancellationToken)
{
Logger.LogWarning("StopAsync");
await Task.Delay(100);
}
}