Lessons in this course (8)

2. 3-tier and N-layer architecture

Basic★ Must knowLesson 2 of 8
text
Presentation layer (UI)      Web Forms pages / MVC controllers & views / API controllers
        ↓ calls
Business Logic Layer (BLL)   services: validation, calculations, workflows
        ↓ calls
Data Access Layer (DAL)      ADO.NET / Dapper / EF repositories, stored procedures
        ↓
Database

Tier vs layer: a layer is a logical separation in code; a tier is a physical deployment unit (browser, web server, database server). A 3-layer app can run on 1, 2 or 3 tiers.

Typical .NET Framework solution:

text
ShopSolution/
├── Shop.Web/                 Web Forms or MVC 5 (UI)
├── Shop.BLL/                 ProductService.cs, OrderService.cs
├── Shop.DAL/                 ProductRepository.cs (ADO.NET), ShopEntities.edmx (EF6)
├── Shop.Entities/ (Models)   Product.cs, Order.cs — shared by all layers
└── Shop.Common/              helpers, constants, logging

Pros: simple, familiar, clear separation. Cons: business logic tends to depend on the DAL (hard to unit test without a database), "anemic" services, changes ripple across layers, everything depends on the database schema.