At startup there is no request or http context, which are typically injected and used by the controller. What ever code you want to call should be refactored to a library call from both the controller and startup.
How to Access a Controller from Startup.cs

lesponce
156
Reputation points
I’m trying to access a controller from the Startup.cs class. This is a .NET Core application running with Angular for the frontend. Can you please advise me how I can access the controller from the Startup class?
I need to execute some code before
public async Task<IActionResult> InitiateProcess(string returnUrl)
{
var hello = _configuration[ConfigSetting];
await = _ServiceProvider.InitiateJobAsync(hello, returnUrl);
return new EmptyResult();
}
Accepted answer
1 additional answer
Sort by: Most helpful
-
lesponce 156 Reputation points
2022-11-08T15:09:59.637+00:00 The application should use the controller so it call an API for authentication. Once the authentication is authorized, the external tool calls another method.
All what I need for now is to call the method listed on the question which is what needs to be called when the application is started.