--- id: wiki-2026-0508-aspnet-core title: ASP.NET Core category: 10_Wiki/Topics status: verified canonical_id: self aliases: [ASP.NET Core, .NET Web, Kestrel, Minimal API] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [dotnet, csharp, web, backend] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: csharp framework: ASP.NET Core 9 / .NET 9 --- # ASP.NET Core ## 매 한 줄 > **"매 cross-platform high-performance 의 .NET 의 web framework"**. 매 Microsoft 의 2016 release 후 의 modular middleware pipeline + Kestrel server + DI built-in 의 design — 매 2026 의 .NET 9 의 native AOT, Minimal API, Blazor United, gRPC 의 first-class support 로 매 enterprise + cloud-native workload 의 dominant choice. ## 매 핵심 ### 매 Architecture - **Kestrel**: 매 cross-platform HTTP server (libuv → managed sockets). - **Middleware pipeline**: 매 request 의 ordered chain — auth, logging, routing, endpoint. - **DI container** (built-in): scoped/singleton/transient. - **Configuration**: appsettings.json + env + secrets + Azure KeyVault 의 layered. - **Hosting model**: Generic Host (`IHostBuilder`) → minimal `WebApplication`. ### 매 API styles 1. **Minimal API** (.NET 6+): top-level, lambda-based — small services 의 default. 2. **MVC controllers**: 매 conventional REST. 3. **Blazor Server / WASM / United** (.NET 8+): full-stack C# UI. 4. **gRPC**: HTTP/2, Protobuf — service-to-service. 5. **SignalR**: WebSocket / long-poll. ### 매 응용 1. REST API (Stripe, Shopify-style backends). 2. gRPC microservice mesh (.NET 9 의 native AOT 의 cold-start fast). 3. Blazor 의 internal admin panel. 4. Azure Functions / AWS Lambda (isolated worker). ## 💻 패턴 ### Minimal API ```csharp var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(o => o.UseNpgsql(builder.Configuration.GetConnectionString("Db"))); builder.Services.AddAuthentication().AddJwtBearer(); var app = builder.Build(); app.MapGet("/users/{id:int}", async (int id, AppDb db) => await db.Users.FindAsync(id) is { } u ? Results.Ok(u) : Results.NotFound()); app.MapPost("/users", async (User u, AppDb db) => { db.Users.Add(u); await db.SaveChangesAsync(); return Results.Created($"/users/{u.Id}", u); }); app.Run(); ``` ### Middleware ```csharp app.Use(async (ctx, next) => { var sw = Stopwatch.StartNew(); await next(); Console.WriteLine($"{ctx.Request.Path} {sw.ElapsedMilliseconds}ms"); }); ``` ### DI + scoped service ```csharp builder.Services.AddScoped(); app.MapGet("/x", (IRepo r) => r.GetAll()); ``` ### Native AOT (.NET 9) ```xml true true ``` - 매 single-file binary, 매 cold-start <10ms, 매 reflection 의 limit. ### Authentication (JWT) ```csharp builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(o => { o.TokenValidationParameters = new() { ValidIssuer = "https://issuer", ValidAudience = "api", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret)) }; }); app.UseAuthentication(); app.UseAuthorization(); app.MapGet("/me", (ClaimsPrincipal u) => u.Identity?.Name).RequireAuthorization(); ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | Small service / prototype | Minimal API | | Complex routing / filters | MVC Controllers | | Service-to-service (internal) | gRPC | | Real-time (chat, dashboard) | SignalR | | Cold-start sensitive (lambda) | Native AOT + Minimal API | | Full-stack C# | Blazor United | **기본값**: 매 Minimal API + EF Core + JWT — 매 modern .NET 의 standard stack. ## 🔗 Graph - 부모: [[.NET]] · [[C#]] - 변형: [[ASP.NET MVC]] · [[Blazor]] · [[gRPC for .NET]] - 응용: [[Azure Functions]] · [[Microservices]] - Adjacent: [[Entity Framework Core]] · [[Kestrel]] · [[SignalR]] ## 🤖 LLM 활용 **언제**: Minimal API endpoint 의 생성, EF Core query 의 LINQ, middleware 의 boilerplate. **언제 X**: 매 native AOT 의 reflection-heavy 의 third-party library 의 compatibility — 매 manual 의 verify. ## ❌ 안티패턴 - **Sync-over-async** (`.Result`, `.Wait()`): 매 thread pool 의 deadlock — 매 `await` 의 사용. - **DbContext singleton**: 매 EF Core 의 not thread-safe — 매 scoped. - **Middleware order 의 random**: 매 auth 의 routing 의 후 — 매 401 의 not enforced. - **Returning IQueryable from controller**: 매 N+1, 매 connection 의 leak. ## 🧪 검증 / 중복 - Verified (learn.microsoft.com/aspnet/core, .NET 9 release notes). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — Minimal API + AOT + JWT patterns |