IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| HTTP Essentials | Distributed Denial-of-Service (DDoS) | |
IActionResult vs ActionResult<T> in ASP.NET Core |
| Feature | IActionResult | ActionResult<T> |
|---|---|---|
| Type | Interface | Generic class inheriting from ActionResult |
| Flexibility | Returns any IActionResult (e.g., Ok(), NotFound()) |
Can return both T and IActionResult |
| IntelliSense Support | Limited for model type T |
Strong — compiler knows expected T |
| Use Case | When returning multiple result types without fixed model | When returning a model <T> and status codes together |
| Introduced In | ASP.NET Core (since MVC days) | ASP.NET Core 2.1+ |
IActionResult
[HttpGet]
public IActionResult GetProduct(int id)
{
var product = _repo.Find(id);
if (product == null)
return NotFound();
return Ok(product);
}
ActionResult<Product>
[HttpGet]
public ActionResult<Product> GetProduct(int id)
{
var product = _repo.Find(id);
if (product == null)
return NotFound();
return product; // Implicitly wrapped in Ok()
}
IActionResultWhen : Full control over response types, no fixed model.
ActionResult when:Cleaner syntax, better Swagger support, model + status code.
T) and still support status codes.
Ok() wrapping.
var result = controller.GetProduct(1); var okResult = Assert.IsType<OkObjectResult>(result.Result); var product = Assert.IsType<Product>(okResult.Value);
| HTTP Essentials | Distributed Denial-of-Service (DDoS) | |