Catalog / ASP.NET Core Cheat Sheet
ASP.NET Core Cheat Sheet
A quick reference guide for ASP.NET Core, covering essential concepts, libraries, and tools for building modern web applications.
Core Concepts
Project Structure
Program.cs: Entry point of the application. Configures the host and startup. |
Views: (MVC) Represent the user interface. |
Dependency Injection
|
Registers a service as a singleton (one instance per application). |
|
Registers a service as scoped (one instance per request). |
|
Registers a service as transient (a new instance every time it’s requested). |
|
Injecting services into controller actions. |
Middleware
Middleware components form the request pipeline. They handle requests and responses.
|
Configuration
Configuration Sources
ASP.NET Core supports various configuration sources:
|
Accessing Configuration
|
Inject |
|
Accessing configuration values. |
|
Binding configuration sections to objects. |
|
Configuring options using the Options pattern. |
Options Pattern
The Options pattern provides a way to access configuration values in a strongly-typed manner.
|
Routing and Controllers
Routing
Routing is responsible for mapping incoming requests to controller actions. Attribute Routing:
Conventional Routing: |
Controllers and Actions
|
Attribute to enable API-specific behaviors. |
|
Return type for controller actions (allows returning different HTTP status codes). |
|
Returns a 200 OK result with a value. |
|
Returns a 400 Bad Request result with an error. |
|
Returns a 404 Not Found result. |
Model Binding
Model binding automatically maps incoming request data to action parameters.
|
Data Access
Entity Framework Core
Entity Framework Core (EF Core) is an ORM for .NET Core.
|
DbContext
|
Represents a collection of entities in the database. |
|
Saves changes to the database. |
|
Adds a new entity to the database. |
|
Removes an entity from the database. |
|
Finds an entity by its primary key. |
LINQ Queries
EF Core uses LINQ (Language Integrated Query) to query the database.
|