I've seen the following declaration of a controller class in one Web API project:
[Route("api/[controller]")]
public class UrlController
{
private readonly IConfiguration configuration;
public UrlController(IConfiguration configuration)
{
this.configuration = configuration;
}
[HttpGet]
[ProducesResponseType(typeof(string), 200)]
public string Get() => this.configuration.GetSection("ShortUrlPrefix").Get<string>();
}
I thought that controllers must inherit from Controller/ControllerBase, but in this case it works without inheritance. Are there any issues with this particular declaration? Is it a kind of "optimization" if we only need to return a simple value (a short string in this case)?