Files
2nd/10_Wiki/Topics/Programming & Language/ASPNET Core.md
T
2026-05-10 22:08:15 +09:00

4.8 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-aspnet-core ASP.NET Core 10_Wiki/Topics verified self
ASP.NET Core
.NET Web
Kestrel
Minimal API
none A 0.9 applied
dotnet
csharp
web
backend
2026-05-10 pending
language framework
csharp 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

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDb>(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

app.Use(async (ctx, next) => {
    var sw = Stopwatch.StartNew();
    await next();
    Console.WriteLine($"{ctx.Request.Path} {sw.ElapsedMilliseconds}ms");
});

DI + scoped service

builder.Services.AddScoped<IRepo, EfRepo>();
app.MapGet("/x", (IRepo r) => r.GetAll());

Native AOT (.NET 9)

<PropertyGroup>
  <PublishAot>true</PublishAot>
  <InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
  • 매 single-file binary, 매 cold-start <10ms, 매 reflection 의 limit.

Authentication (JWT)

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