0% found this document useful (0 votes)
3 views2 pages

Sample

This document provides a quick reference for ASP.NET Core, covering controller basics, HTTP action verbs, dependency injection, minimal API setup, common return types, and a checklist for implementation. It emphasizes the use of attributes like [ApiController] and [Route] for controllers, as well as the registration of services in Program.cs. The document serves as a guide for creating and managing APIs in ASP.NET Core applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Sample

This document provides a quick reference for ASP.NET Core, covering controller basics, HTTP action verbs, dependency injection, minimal API setup, common return types, and a checklist for implementation. It emphasizes the use of attributes like [ApiController] and [Route] for controllers, as well as the registration of services in Program.cs. The document serves as a guide for creating and managing APIs in ASP.NET Core applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ASP.

NET Core — Quick Reference


Sample PDF for file result practice · May 2026

1. Controller Basics
A controller in [Link] Core must be a public class that inherits ControllerBase (for APIs) or
Controller (for MVC views). Annotate it with [ApiController] and [Route] to enable automatic model
binding, validation, and routing.

Minimal working controller:

[ApiController] [Route("api/[controller]")] public class ProductsController :


ControllerBase { [HttpGet("{id}")] public IActionResult GetById(int id) =>
Ok(new { Id = id, Name = "Widget" }); }

2. HTTP Action Verbs


Attribute HTTP Verb Typical Use

[HttpGet] GET Read / query data

[HttpPost] POST Create a resource

[HttpPut] PUT Replace a resource

[HttpPatch] PATCH Partial update

[HttpDelete] DELETE Remove a resource

3. Dependency Injection
Register services in [Link] using one of three lifetimes:

Lifetime Method When to use

Transient AddTransient<T>() Lightweight, stateless services

Scoped AddScoped<T>() Per-HTTP-request (e.g., DbContext)

Singleton AddSingleton<T>() Shared app-wide state / config


4. [Link] — Minimal API Setup
[Link] Core 6+ uses a single [Link] (no Startup class). The builder pattern wires services; the
app pipeline is configured with Use… extension methods.

var builder = [Link](args);


[Link]();
[Link](); [Link]();
var app = [Link](); if ([Link]())
[Link]().UseSwaggerUI(); [Link]();
[Link](); [Link](); [Link]();

5. Common Return Types


Return type Status code Example

Ok(value) 200 Successful GET

Created(uri,val) 201 POST created resource

NoContent() 204 Successful DELETE

BadRequest(msg) 400 Validation failure

NotFound() 404 Resource missing

StatusCode(n) any Custom codes

6. Quick Checklist
■ Controller class is public and inherits ControllerBase

■ [ApiController] attribute is present

■ Route template defined via [Route] or inside the verb attribute

■ Action methods declare an explicit HTTP verb ([HttpGet] etc.)

■ Services registered in [Link] before [Link]()

■ [Link]() called before [Link]()

Generated for file-result practice — [Link] Core 8 · .NET 8

You might also like