So I've created an API project using .NET Core 3 and inside the project I've created a Controller like so:
[Route("api/account")]
[ApiController]
public class AccountController : ControllerBase
{
public IActionResult Hello()
{
return Ok("Hello");
}
}
In my Startup.cs I have:
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
From what I understand, the line services.AddControllers(); picks up every controller in my api project. I remember in asp.net to add controllers you would have to call this line:
services.AddTransient<AccountController>();
You would have to namely add each controller, is there no way to do this in .NET Core 3?