Series: From Code to Cloud: Building a Production-Ready .NET Application
By: Farrukh Rehman — Senior .NET Full Stack Developer / Team Lead
LinkedIn: https://linkedin.com/in/farrukh-rehman
GitHub: https://github.com/farrukh1212cs
🚀 Introduction
In this lesson, we’ll lay the foundation for our eCommerce enterprise application by setting up the base solution and API project in .NET. A solid foundation is crucial for scalability and maintainability — especially when your application is expected to grow into multiple services or environments.
We’ll walk through creating the core project structure, organizing folders for clarity and separation of concerns, configuring dependency injection, and managing environment-specific settings for smooth local and production deployments.
By the end of this lesson, you’ll have a clean, well-structured ASP.NET Core API that’s ready to evolve into a robust, enterprise-grade system.
🧱 Clean Architecture Layers
🧩 High-Level System Overview
🧰 Initial Setup
mkdir ECOMMERCE
cd ECOMMERCE
dotnet new sln -n ECommerce
dotnet new webapi -n ECommerce.API
dotnet new classlib -n ECommerce.Application
dotnet new classlib -n ECommerce.Domain
dotnet new classlib -n ECommerce.Infrastructure
dotnet sln add ECommerce.API\ECommerce.API.csproj
dotnet sln add ECommerce.Application\ECommerce.Application.csproj
dotnet sln add ECommerce.Domain\ECommerce.Domain.csproj
dotnet sln add ECommerce.Infrastructure\ECommerce.Infrastructure.csproj
dotnet add ECommerce.API reference ECommerce.Application
dotnet add ECommerce.Application reference ECommerce.Domain
dotnet add ECommerce.Infrastructure reference ECommerce.Application
dotnet add ECommerce.Infrastructure reference ECommerce.Domain
🧩 Solution Structure Overview
Here’s what your Visual Studio solution looks like — containing 4 core projects, each serving a distinct purpose in the architecture:
- 🧱 ECommerce.API This is the entry point of your application — where all HTTP requests come in.
Contains:
Program.cs → The starting point of the application. It wires up services, middleware, and dependency injection.
appsettings.json → The main configuration file for production or default environment settings (e.g., database connection strings, API keys).
appsettings.Development.json → Environment-specific overrides for local development (e.g., local DB connection or mock API URLs).
launchSettings.json → Stores information about how the app runs locally (ports, profiles, environment).
ECommerce.API.http → A test file for making quick API calls directly from Visual Studio.
WeatherForecast → Default example controller that comes with the Web API template (you can delete this once you create your own controllers).
🔹 Purpose: Acts as the Presentation Layer — exposing API endpoints, handling requests, and returning responses.
- ⚙️ ECommerce.Application This is where business logic and use cases live. Think of it as the brain of your system — containing services that implement business operations.
You’ll add here:
- Service classes (e.g., ProductService, OrderService)
- DTOs (Data Transfer Objects)
- Validation logic
- Interfaces that define contracts for repositories
🔹 Purpose: Holds your application logic — independent from UI, database, or frameworks.
- 🧩 ECommerce.Domain This layer defines your core entities and business rules — the heart of your system.
You’ll add here:
- Entities (e.g., Product, Customer, Order)
- Value Objects (e.g., Money, Address)
- Domain Interfaces (e.g., IAggregateRoot, IBaseEntity)
- Enums or domain-specific constants
🔹 Purpose: Represents pure business logic, without dependencies on databases, APIs, or frameworks.
This layer is completely independent and reusable.
- 🗄️ ECommerce.Infrastructure This layer deals with external resources and persistence (databases, file storage, external APIs).
You’ll add here:
- Repository implementations
- Database context (e.g., ECommerceDbContext)
- EF Core migrations
- Logging, Email, or Third-Party Service integrations
🔹 Purpose: Implements the data access and infrastructure logic that supports the Application layer.
🔁 Relationships Between Layers
API Layer → Application Layer
Application Layer → Domain Layer
Application Layer → Infrastructure Layer (through interfaces)
Each layer depends only on the one below it, never upward — ensuring separation of concerns and maintainability.
🧰 Build & Run
Now that our base solution and projects are ready, let’s build and run the application to verify everything works correctly.
🧭 Adding Swagger for API Documentation
Swagger (now known as OpenAPI) is a great tool to visualize and test your REST APIs.
- Install Swagger NuGet Package
dotnet add ECommerce.API package Swashbuckle.AspNetCore --version 6.6.2
🧹 Clean Program.cs
⚙️ launchSettings.json (Clean & Fixed)
🏁 Next Step
Start with Lesson 2B— Implementing Domain Entities in Clean Architecture (.NET 8) Creating Core Business Models — Customer, Order, OrderItem, and Product
Top comments (0)