</>
Skip to content
ASP lessons (32/40)

ASP — ASP.NET Core

What is ASP.NET Core?

ASP.NET Core is a cross-platform, high-performance framework for building web apps.

Create Project

dotnet new webapp -n MyApp
cd MyApp
dotnet run

Program.cs

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello, World!");

app.Run();

Controller

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    [HttpGet]
    public IActionResult Get()
    {
        return Ok(new[] { "John", "Jane" });
    }
    
    [HttpPost]
    public IActionResult Post([FromBody] User user)
    {
        return CreatedAtAction(nameof(Get), user);
    }
}

Dependency Injection

builder.Services.AddScoped<IUserService, UserService>();

app.MapGet("/users", (IUserService service) => service.GetAll());

Mini Practice

  1. Create project
  2. Create API controller
  3. Use dependency injection
  4. Run the application

Up Next

Continue with ASP.NET Web API — Web API.

Related Topics

Frequently Asked Questions about ASP.NET Core

What is ASP.NET Core in ASP?

ASP.NET Core is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn ASP.NET Core?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ASP.NET Core.

Why is ASP.NET Core important in ASP?

ASP.NET Core is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.