Call a Method inside Controller

lesponce 176 Reputation points
2022-03-07T16:49:00.81+00:00

I got a .NET Core application, using Angular as a frontend. I have a controller that needs to be triggered before the website is launched. In order to make that happen, I wish I could call the method inside the controller from the Startup class, but it seems to be a bad practice.

How can accomplish this? Can you please provide me an line of code on how to call a method that is inside a controller?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,157 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. lesponce 176 Reputation points
    2022-03-07T19:24:27.103+00:00

    The class that I need to call is inside a controller. That class is coded like this:

    public async Task<IActionResult> InitiateSignOn(string returnUrl = null)
    {
    var partnerName = _configuration[PartnerName];
    await = _ServiceProvider.InitatiateSignOn(partnerName, returnUrl);

    return new EmptyReturn();
    

    }

    So if I move the above class into a Helper Class. Then, I'm not sure if the code in controller would work. Please advise. Thanks