Код: Выделить всё
public class MyService: IMyService
{
private string myToken;
public MyService()
{
}
public void SetMyToken(string token)
{
Console.WriteLine($"This is the parameter token: {token}");
myToken = token;
Console.WriteLine($"This is myToken: {myToken}");
}
public async Task TriggerPipeline()
{
Console.WriteLine($"Calling TriggerPipeline function. myToken: {myToken}");
// the rest of the code
}
}
Код: Выделить всё
[Route("[controller]")]
[ApiController]
public class MyController: ControllerBase
{
private readonly IMyService _myService;
public MyController(IMyService myService,)
{
_myService = myService;
}
[HttpGet("set-token")]
public async Task SetToken(string token)
{
_myService.SetMyToken(token);
return Ok("Token set successfully");
}
[HttpPost("trigger-pipeline")]
public async Task TriggerPipeline()
{
// the rest of the code
}
}
Код: Выделить всё
This is the parameter token: 123
This is myToken: 123
Calling TriggerPipeline function. myToken:
Код: Выделить всё
"123"). Однако после еще одного Http-вызова TriggerPipelineВ моем Program.cs я уже использую Scoped Services:< /p>
Код: Выделить всё
builder.Services.AddScoped();
Подробнее здесь: https://stackoverflow.com/questions/790 ... uests-in-c
Мобильная версия