COMPUTER ENGINEER

Jump to examples
Blog
Next.js / ASP.NET Core / SQL6 min study
20/ 41

The application layer

Layers: Domain, Application, Infrastructure

This project’s backend is split into four projects. Why, and which way do dependencies point?

UnderstandStudy an examplePractise

Understand the concept

This site’s API consists of four projects. Domain holds business concepts (post, project, message) and their rules and depends on no framework. Application defines use cases (get a published post, store a message) and the interfaces they need, exposing data transfer objects (DTOs) outward. Infrastructure contains concrete implementations of those interfaces: the EF Core DbContext, SQL queries, file storage. Api is the outermost layer connecting HTTP to Application.

Dependencies point inward: Api and Infrastructure know Application; Application knows Domain; Domain knows no one. Business rules are therefore unaffected when the database or web framework changes and can be tested without a framework.

Layering is a tool, not a goal. In a small project four layers can be needless ceremony. But in a system with an admin panel, bilingual content, caching and security rules, knowing clearly where each responsibility lives makes changes safe.

WHEN TO USE IT

A clear home for each responsibility keeps changes small and predictable.

COMMON PITFALL

Adding EF Core or ASP.NET Core references to the Domain project, tying the core to a framework.

01 / PRACTICE

One topic. Three levels of depth.

Illustrative example
backend/
  AtaberkSahin2.Domain/          Content.cs (varlıklar, kurallar)
  AtaberkSahin2.Application/     ContentContracts.cs, Queries/ (DTO, arayüzler)
  AtaberkSahin2.Infrastructure/  PortfolioDbContext.cs, ContentStore.cs
  AtaberkSahin2.Api/             Controllers/, Middleware/, Program.cs

This project’s real folder structure.

This page connects to no real server or database. Code samples are illustrative for .NET 8, Next.js and SQL Server; timings are example values in the simulation, not measurements. Try samples only in your own development environment; never share real connection strings, tokens or passwords.

02 / YOUR TURN

Try it yourself first.

When publishing a post the rule is ‘title cannot be empty and the publish date cannot be in the future’. Which layer should own it?

Show the solution and explanation
Worked solution
Domain (veya Application’daki kullanım senaryosu).
Controller yalnız girdiyi alır; kural, HTTP’den bağımsız
bir yerde olmalı ki yönetim paneli, içe aktarma veya arka plan işi aynı kuralı kullansın.

A business rule lives close to the core so it applies no matter which channel triggers it.