Project Setup for Microservices in ASP.NET Core Web API

Project Setup for Microservices in ASP.NET Core Web API

In this article, I will explain the Project Setup for Microservices in ASP.NET Core Web API. Modern e-commerce platforms are built to handle millions of users and thousands of transactions daily. To achieve flexibility, scalability, and ease of maintenance, these systems are developed using a microservices architecture.

In this post, I will provide a step-by-step guide to setting up an e-commerce project in Visual Studio using the microservices approach. Each microservice focuses on a specific business capability, such as user management, product catalog, order processing, payments, or notifications, enabling independent development and deployment. By following Clean Architecture and Domain-Driven Design principles, this setup ensures a solid foundation for building robust, maintainable, and scalable e-commerce solutions.

What is an E-Commerce Application?

An e-commerce application (such as Amazon, Flipkart, or Myntra) is an online platform where users can browse products, place orders, make payments, and receive notifications. It handles interactions between buyers and sellers digitally, automating key business processes such as product catalog management, order processing, payment transactions, and communication. Key Features Include:

  • Product browsing & search
  • User accounts and profiles
  • Shopping carts & order placement
  • Secure payments
  • Order tracking & notifications

Behind the scenes, a modern e-commerce system is usually built with multiple independent services (microservices), each handling a specific business capability. This separation allows for flexibility, scalability, and easier maintenance. The following are the key Microservices present in an eCommerce Application.

User Microservice

It manages user-related functionality, including registration, authentication, profile management, and authorization. The following are some of the Key Features of User Microservice:

  • User registration (sign up) and login (authentication)
  • Password management and reset
  • Role management (e.g., Admin, Customer, Vendor)
  • Address management (multiple shipping/billing addresses)
  • Security with JWT tokens or OAuth2
  • Multi-factor authentication and social login integration

Why it’s important: User identity and security are the foundation of any eCommerce platform. This service ensures that only authenticated users can perform actions like placing orders or managing profiles.

Product Microservice

Handles the product catalog, including product details, categories, pricing, inventory, and reviews. The following are some of the Key Features of Product Microservice:

  • CRUD operations for products (add, update, delete, list)
  • Organizing products into categories and subcategories
  • Managing product inventory (stock levels)
  • Product images and descriptions
  • Search and filter by name, category, price, and more.
  • Price and discount management
  • Customer reviews and ratings

Why it’s important: It provides the data layer for what users browse and buy. Accurate product and inventory data directly impacts customer experience and sales.

Order Microservice

Manages the lifecycle of customer orders from placement to delivery. The following are  some of the Key Features of Order Microservice:

  • Order creation (when a customer checks out)
  • Order status tracking (Placed, Confirmed, Shipped, Delivered, Cancelled)
  • Cart management and validation (checking product availability/prices)
  • Order history for users
  • Managing returns and cancellations
  • Integration with Payment and Notification services

Why it’s important: The heart of eCommerce operations, it tracks what customers buy and ensures smooth processing and fulfilment.

Payment Microservice

Handles all payment processing and transaction management. The following are some of the Key Features of the Payment Microservice:

  • Handling different payment methods (Card, UPI, Net Banking, Wallet, etc.)
  • Payment processing and transaction management
  • Payment authorization, capture, refund, and failure handling
  • Secure storage of sensitive payment information (PCI compliance)
  • Notification of payment results to the Order service

Why it’s important: Ensures secure, reliable, and flexible payment processing, which is critical for revenue collection and customer trust.

Notification Microservice

Sends notifications to users via multiple channels. The following are some of the Key Features of the Notification Microservice:

  • Email, SMS, push notifications
  • Templated messages for order confirmation, shipment, and payment receipts
  • Event-driven architecture listening to order, payment events
  • Retry and failure handling
  • User preferences for notification types

Why it’s important: Keeps users informed in real-time, improving engagement and customer satisfaction.

Recommended Development Approach (Order of Development)
  1. User Service (First): Start with user registration and authentication. Almost all other services depend on user identity.
  2. Product Service (Second): Populate your catalog with products to showcase and sell.
  3. Order Service (Third): Once users and products are in place, enable order placement and management.
  4. Payment Service (Fourth): Integrate payment after orders can be placed, linking payments to orders.
  5. Notification Service (Last): Build notifications last to inform users about activities from other services.
Development Approaches for Microservices

When building microservices, how you organize your codebase and projects significantly impacts your development workflow, team collaboration, and deployment processes. Two popular approaches are:

  • Single Common Solution (Monorepo Style)
  • Separate Solutions Per Microservice (Polyrepo Style)
Single Common Solution (Monorepo Style)

One big Visual Studio solution (.sln) contains all microservices as projects. Each microservice (e.g., Product, User, Order) is just a folder or project inside the same solution. Each microservice typically consists of multiple projects (Domain, Application, Infrastructure, and API) within a single solution. Developers clone and work on the entire codebase at once.

It’s like all your different shops (Product, Order, User) are inside the same big building. They can quickly borrow things from each other because everything is under one roof.

Advantages:
  • Easy local setup and navigation, all microservices in one place.
  • Simplifies cross-service debugging and refactoring.
  • Shared libraries or common code can be easily referenced in projects without the need to publish packages.
  • Better suited for smaller teams or early-stage projects that require fast-paced development.
Disadvantages:
  • As the project grows, the solution can become large and slow to load or build.
  • Potential for merge conflicts and coordination overhead among teams working on different microservices.
  • Deploying individual microservices independently can be more complex if not properly managed.
Separate Solutions Per Microservice (Polyrepo Style)

Each microservice is developed in its own independent repository with its own Visual Studio solution. Projects within each microservice solution adhere to Clean Architecture layers but are self-contained. Microservices are built, tested, and deployed independently.

Now, each shop (Product, Order, User) is in its own building. They talk to each other via phone or email (API, messaging), but each can be locked, renovated, or scaled independently. If one shop is down, the others continue to run.

Advantages:
  • With clear boundaries and ownership, each team can work independently.
  • Smaller, faster-loading solutions.
  • Enables independent versioning and deployment pipelines per microservice.
  • Reduces cross-team merge conflicts and allows for more scalable team growth.
Disadvantages:
  • Sharing common code or contracts requires separate packages or submodules, adding complexity.
  • Cross-microservice debugging and refactoring are more difficult.
  • Initial setup and infrastructure for multiple repos can be more complex.
Industry Trend & Best Practice (with Clean Architecture & DDD)

The best practice is: One Solution/Repo Per Microservice (Polyrepo)

  • Each microservice (Product, Order, User, Payment, etc.) lives in its own Git repository and has its own .sln file.
  • Each solution is organized using Clean Architecture and DDD inside that microservice.
  • Each microservice is built, tested, and deployed independently.

Why?

  • Aligns with microservices principles: Independent deployment, decentralized data, team ownership.
  • Clean Architecture and DDD: Each microservice owns its own domain model, logic, and boundaries, matching the principles of DDD.
  • Loose coupling: Forces all inter-service communication to use network protocols (e.g., HTTP, gRPC, messaging), with no shortcuts.
  • Scalability: Teams and services scale naturally, without overlapping or competing with each other.

What about shared code?

  • Use internal NuGet Packages (published to private registries) for features such as logging abstractions, base entities, or error contracts.
  • Avoid large, shared “common” libraries; only package things that are truly generic and stable.
What Approach will we use in our Course?

We will start with a single common Visual Studio solution that contains all our microservices projects (API + Domain + Application + Infrastructure per microservice). We will use this common solution during our course and development to simplify coding, debugging, and learning Clean Architecture and DDD.

As our project grows, we will extract each microservice into its own solution or repository when independent deployments become a priority. For production or enterprise environments, it is considered best practice to have separate solutions or repositories for each microservice to ensure operational independence.

Project Setup:

Create an eCommerce system Solution with Microservices. Again, each Microservice is composed of 5 projects as follows.

  • Domain (Class Library)
  • Application (Class Library)
  • Infrastructure (Class Library)
  • API (ASP.NET Core Web API)
  • Tests (xUnit Test Project)
Step 1: Create the Root Solution
  1. Open Visual Studio.
  2. Click File > New > Project.
  3. Search for Blank Solution and select it.
  4. Click Next.
  5. Name the solution ECommerceSystem.
  6. Choose a location where you want to save the solution (e.g., D:\Projects\ECommerceSystem).
  7. Click Create.
Step 2: Create Solution Folders for Microservices
  1. In Solution Explorer, right-click on the Solution (ECommerceSystem).
  2. Choose Add > New Solution Folder.
  3. Name it UserService.
  4. Repeat steps 1-3 for the other microservices folders:
    • ProductService
    • OrderService
    • PaymentService
    • NotificationService

You should now see your solution with 5 solution folders as shown in the image below.

Project Setup for Microservices in ASP.NET Core Web API

Step 3: Add Projects for UserService (Repeat for Others)

Let’s walk through one microservice (UserService) and then repeat the process for the others.

Add Domain Project
  1. Right-click the solution folder (e.g., UserService).
  2. Select Add > New Project.
  3. Choose Class Library (.NET Core) template and (.NET 8) Framework version.
  4. Name it UserService.Domain.
  5. Click Create.
Add Infrastructure Project
  1. Right-click the solution folder (e.g., UserService).
  2. Select Add > New Project.
  3. Choose Class Library (.NET Core) template and (.NET 8) Framework version.
  4. Name it UserService.Infrastructure.
  5. Click Create.

Add Project Reference: Right-click UserService.Infrastructure → Add → Project Reference → Check UserService.Domain.

Add Application Project
  1. Right-click the solution folder (e.g., UserService).
  2. Select Add > New Project.
  3. Choose Class Library (.NET Core) template and (.NET 8) Framework version.
  4. Name it UserService.Application.
  5. Click Create.

Add Project Reference: Right-click UserService. Application → Add → Project Reference → Check UserService.Domain and UserService.Application.

Add API Project
  1. Right-click the solution folder (e.g., UserService).
  2. Select Add > New Project.
  3. Choose the ASP.NET Core Web API template and the .NET 8 Framework version.
  4. Name it UserService.API.
  5. Click Create.

Add References: Right-click UserService.API → Add → Project Reference → Check UserService.Application and UserService.Infrastructure.

Add Tests Project (xUnit)
  • Right-click the UserService solution folder → Add → New Project.
  • Choose xUnit Test Project (.NET Core) and (.NET 8) Framework version.
  • Name: UserService.Tests
  • Click Create.

Add References: Right-click UserService.Tests → Add → Project Reference → Check UserService.Domain, UserService.Application (and UserService.Infrastructure if you wish to do integration tests).

With this, your project solution should look as follows:

Project Setup for Microservices in ASP.NET Core Web API

Do the same for other Services with the following naming conventions:

ProductService – Solution Folder
  • ProductService.Domain
  • ProductService.Infrastructure
  • ProductService.Application
  • ProductService.API
  • ProductService.Tests
OrderService – Solution Folder
  • OrderService.Domain
  • OrderService.Infrastructure
  • OrderService.Application
  • OrderService.API
  • OrderService.Tests
PaymentService – Solution Folder
  • PaymentService.Domain
  • PaymentService.Infrastructure
  • PaymentService.Application
  • PaymentService.API
  • PaymentService.Tests
NotificationService – Solution Folder
  • NotificationService.Domain
  • NotificationService.Infrastructure
  • NotificationService.Application
  • NotificationService.API
  • NotificationService.Tests

The following is the complete folder structure with all microservices.

Project Setup for Microservices using ASP.NET Core Web API

By organizing our e-commerce application into dedicated microservices within a single Visual Studio solution, we gain the benefits of clear separation of concerns, easier code management, and scalable team collaboration.

This project structure not only streamlines the development process but also aligns with industry standards for building modern distributed systems. As our project evolves, we can further enhance scalability and independence by transitioning to separate solutions and repositories for each microservice.

In the next article, I will discuss how to create a User Microservice. In this article, I try to explain the Project Setup for Microservices using ASP.NET Core Web API. I hope you enjoy this Project Setup for Microservices using the ASP.NET Core Web API article.

Leave a Reply

Your email address will not be published. Required fields are marked *