Files
indotalent-webstore/blog/vsa-introduction.html
T
2026-07-21 10:12:35 +07:00

147 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en" itemscope itemtype="https://schema.org/Article">
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-G9G5HP50VK"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-G9G5HP50VK');</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Introduction to Vertical Slice Architecture in .NET 10 | Indotalent Blog</title>
<meta name="description" content="Learn how Vertical Slice Architecture (VSA) organizes .NET 10 code by business features instead of technical layers. Complete with Minimal API code examples." />
<meta name="keywords" content="Vertical Slice Architecture, VSA .NET 10, Minimal API, MediatR, CQRS, enterprise architecture, .NET architecture patterns" />
<meta name="robots" content="index, follow" />
<link rel="canonical" href="https://www.indotalent.com/blog/vsa-introduction.html" />
<link rel="alternate" hreflang="en" href="https://www.indotalent.com/blog/vsa-introduction.html" />
<link rel="alternate" hreflang="x-default" href="https://www.indotalent.com/blog/vsa-introduction.html" />
<meta property="og:title" content="Introduction to Vertical Slice Architecture in .NET 10" />
<meta property="og:description" content="Learn how VSA organizes .NET 10 code by business features. Complete with code examples." />
<meta property="og:type" content="article" />
<meta name="twitter:card" content="summary_large_image" />
<link rel="icon" type="image/x-icon" href="../favicon.ico" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Introduction to Vertical Slice Architecture in .NET 10",
"description": "How VSA organizes code by business features, why it beats layered architecture, and concrete .NET 10 Minimal API examples.",
"author": { "@type": "Person", "name": "go2ismail" },
"datePublished": "2026-06-01",
"publisher": { "@type": "Organization", "name": "Indotalent" }
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://www.indotalent.com/" },
{ "@type": "ListItem", "position": 2, "name": "Blog", "item": "https://www.indotalent.com/blog/" },
{ "@type": "ListItem", "position": 3, "name": "Introduction to Vertical Slice Architecture in .NET 10", "item": "https://www.indotalent.com/blog/vsa-introduction.html" }
]
}
</script>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script>tailwind.config={theme:{extend:{colors:{brand:{50:'#fff7ed',100:'#ffedd5',200:'#fed7aa',300:'#fdba74',400:'#fb923c',500:'#f97316',600:'#ea580c',700:'#c2410c'}},fontFamily:{sans:['Inter','system-ui','sans-serif']}}}}</script>
<style>
.nav-blur{backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
.gradient-text{background:linear-gradient(135deg,#f97316,#ea580c);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
.btn-primary{display:inline-flex;align-items:center;justify-content:center;background:linear-gradient(135deg,#f97316,#ea580c);color:#fff;font-weight:600;border-radius:12px;padding:12px 24px;transition:all 0.2s;box-shadow:0 4px 14px -4px rgba(249,115,22,0.35);text-decoration:none}
.btn-primary:hover{transform:translateY(-1px);box-shadow:0 8px 20px -4px rgba(249,115,22,0.45)}
article h2{font-size:1.5rem;font-weight:700;margin:1.75rem 0 0.75rem;color:#111827}
article h3{font-size:1.15rem;font-weight:600;margin:1.5rem 0 0.5rem;color:#1f2937}
article p{font-size:0.95rem;line-height:1.8;color:#4b5563;margin-bottom:1rem}
article code{background:#f3f4f6;padding:2px 6px;border-radius:4px;font-size:0.85rem;color:#ea580c}
article pre{background:#1f2937;color:#f9fafb;padding:16px;border-radius:10px;overflow-x:auto;margin:1rem 0;font-size:0.85rem;line-height:1.6}
article ul{list-style:disc;padding-left:1.5rem;margin-bottom:1rem}
article ul li{font-size:0.95rem;line-height:1.8;color:#4b5563}
</style>
</head>
<body class="bg-white text-gray-900 antialiased">
<nav aria-label="Breadcrumb" class="pt-20 bg-white border-b border-gray-100">
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-2.5">
<ol class="flex items-center gap-1.5 text-xs text-gray-400">
<li><a href="../index.html" class="hover:text-brand-500 transition-colors">Home</a></li>
<li><span class="text-gray-300">/</span></li>
<li><a href="index.html" class="hover:text-brand-500 transition-colors">Blog</a></li>
<li><span class="text-gray-300">/</span></li>
<li><span class="text-gray-600 font-medium">VSA Introduction</span></li>
</ol>
</div>
</nav>
<nav class="fixed top-0 left-0 right-0 z-50 nav-blur bg-white/85 border-b border-gray-200/60">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"><div class="flex items-center justify-between h-16"><a href="../index.html" class="flex items-center gap-2.5"><img src="../img/logo-indotalent-dark.svg" alt="Indotalent" class="h-8 w-auto" /></a><div class="hidden lg:flex items-center gap-6"><a href="../index.html#products" class="text-sm font-medium text-gray-600 hover:text-brand-500">Products</a><a href="../for-beginners.html" class="text-sm font-medium text-gray-600 hover:text-brand-500">Beginners</a><a href="../for-freelancers.html" class="text-sm font-medium text-gray-600 hover:text-brand-500">Freelancers</a><a href="index.html" class="text-sm font-medium text-brand-600">Blog</a></div></div></div>
</nav>
<section class="pt-24 pb-10 lg:pt-32 lg:pb-12">
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center gap-2 mb-3"><span class="text-xs font-semibold bg-amber-50 text-amber-700 border border-amber-200 rounded-full px-2.5 py-0.5">VSA</span><span class="text-xs text-gray-400">June 2026 · 8 min read</span></div>
<h1 class="text-3xl sm:text-4xl font-extrabold text-gray-900 mb-4">Introduction to Vertical Slice Architecture in .NET 10</h1>
<div class="bg-green-50 border border-green-200 rounded-xl p-4 mb-8">
<p class="text-sm text-green-800 font-semibold mb-1">TL;DR</p>
<p class="text-sm text-green-700">Vertical Slice Architecture organizes code by business features instead of technical layers. In .NET 10, you can define an entire feature — endpoint, DTOs, validation, and handler — in <strong>a single C# file</strong>. This maximizes cohesion, reduces cognitive overhead, and lets you add features without touching 7 different projects.</p>
</div>
<article>
<p>Vertical Slice Architecture (VSA) is a software design approach that organizes code by business features rather than technical layers. In a traditional layered architecture, implementing a "Create Order" feature means working across <code>Controllers/</code>, <code>Services/</code>, <code>Repositories/</code>, <code>Domain/</code>, and <code>DTOs/</code> — often spread across 5+ separate projects. VSA flips this on its head: everything for "Create Order" lives in one folder, one file, or at most a small cluster of files within a single project.</p>
<h2>Why VSA Matters in .NET 10</h2>
<p>.NET 10's Minimal APIs make VSA more natural than ever. You can define an entire feature — endpoint, request/response DTOs, validation, and handler logic — in a single C# file using top-level statements and MediatR. The result is maximum cohesion: everything you need to understand a feature is in one place. No more jumping between 7 projects in Solution Explorer just to trace a single user action.</p>
<h3>Key Benefits</h3>
<ul>
<li><strong>Maximum Cohesion:</strong> All code for a feature lives together. When you need to modify "Create Order," you open one file.</li>
<li><strong>Faster Onboarding:</strong> New developers understand a feature by reading a single file, not tracing through 5 projects.</li>
<li><strong>Reduced Merge Conflicts:</strong> Teams working on different features rarely touch the same files.</li>
<li><strong>Easier Testing:</strong> Each slice is self-contained and can be tested in isolation.</li>
</ul>
<h2>A Concrete Example</h2>
<pre>// Features/Orders/CreateOrder.cs
public static class CreateOrderEndpoint
{
public static void Map(IEndpointRouteBuilder app) =>
app.MapPost("/api/orders", async (CreateOrderCommand cmd, IMediator m) =>
Results.Ok(await m.Send(cmd)));
}
public record CreateOrderCommand(string CustomerId, List<OrderItem> Items) : IRequest<OrderDto>;
public class CreateOrderHandler : IRequestHandler<CreateOrderCommand, OrderDto>
{
readonly AppDbContext _db;
public CreateOrderHandler(AppDbContext db) => _db = db;
public async Task<OrderDto> Handle(CreateOrderCommand cmd, CancellationToken ct)
{
var order = Order.Create(cmd.CustomerId, cmd.Items);
_db.Orders.Add(order);
await _db.SaveChangesAsync(ct);
return OrderDto.FromEntity(order);
}
}</pre>
<p>That's it. One file contains the API endpoint, the command, the handler, and the result DTO. When you need to modify how orders are created, you open this file. When a new developer joins, they read this file and understand the entire flow. This is the power of VSA.</p>
<h2>Key Takeaways</h2>
<ul>
<li>VSA organizes by <strong>business capability</strong>, not technical concern</li>
<li>.NET 10 Minimal APIs + MediatR make VSA natural and concise</li>
<li>Every Indotalent product uses this architecture — study real production code</li>
<li>One file = one feature = zero confusion</li>
</ul>
</article>
<div class="mt-10 p-6 bg-gradient-to-r from-orange-50 to-amber-50 border border-orange-200 rounded-2xl">
<p class="text-sm text-gray-700 font-semibold mb-2">Ready to study real VSA code?</p>
<p class="text-sm text-gray-600 mb-4">Every Indotalent product is a complete .NET 10 application built with Vertical Slice Architecture. Complete source code — $21 each.</p>
<a href="../index.html#products" class="btn-primary text-sm">Explore Products</a>
</div>
<div class="mt-6"><a href="index.html" class="text-sm text-brand-600 hover:text-brand-700">&larr; Back to Blog</a></div>
</div>
</section>
<footer class="bg-white border-t border-gray-200"><div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-10"><div class="flex flex-col md:flex-row items-center justify-between gap-4"><a href="../index.html" class="flex items-center gap-2"><img src="../img/logo-indotalent-dark.svg" alt="Indotalent" class="h-5 w-auto" /></a><div class="flex flex-wrap gap-4 text-sm"><a href="../index.html#products" class="text-gray-500 hover:text-brand-500">Products</a><a href="index.html" class="text-gray-500 hover:text-brand-500">Blog</a><a href="../support.html" class="text-gray-500 hover:text-brand-500">Support</a></div><p class="text-xs text-gray-500">&copy; 2024-2026 Indotalent. <span class="text-brand-500">&hearts;</span> by go2ismail</p></div></div></footer>
</body>
</html>