LESSON 2 OF 22

2. Creating the .NET 10 Solution and Layer Projects

In this lesson, you will create the .NET 10 Clean Architecture solution, add the Domain, Application, Infrastructure, and API projects, and configure their dependencies.

45 dk 99

Introduction

In the previous lesson, we examined the project requirements and the core ideas behind Clean Architecture. In this lesson, we will turn that conceptual design into a real .NET 10 solution. The goal is not simply to create four folders. We will define responsibility boundaries, control the direction of project dependencies, and prepare a foundation that can grow with the application.

By the end of the lesson, the solution will contain four projects: Domain, Application, Infrastructure, and API. The Domain project will contain the central business concepts, the Application project will coordinate use cases, the Infrastructure project will contain database and external technology details, and the API project will serve as the HTTP entry point.

With the .NET 10 SDK, dotnet new sln can create the SLNX solution format by default. .NET 10 also provides the dotnet reference add command for adding project references. If you are using .NET 9 or an earlier SDK, use the older dotnet add reference form instead. ([learn.microsoft.com](https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/10.0/dotnet-new-sln-slnx-default?utm_source=openai))

Solution, project, and layer

A solution is a container that organizes multiple projects belonging to the same application. It does not execute business code itself; instead, it keeps projects together and tracks their build relationships.

A project is a buildable unit. A class library produces an assembly, while an ASP.NET Core Web API project produces a web application. Each project has its own .csproj file that describes its target framework, references, and build settings.

A layer describes a responsibility boundary. In Clean Architecture, each major boundary is represented by a separate project. This makes architectural rules visible in the file system and enforceable through project references and the compiler.

Target solution structure

We will name the solution CleanArchitectureDemo. The initial structure will look like this:

CleanArchitectureDemo/
├── CleanArchitectureDemo.slnx
├── src/
│   ├── Domain/
│   │   └── CleanArchitectureDemo.Domain.csproj
│   ├── Application/
│   │   └── CleanArchitectureDemo.Application.csproj
│   ├── Infrastructure/
│   │   └── CleanArchitectureDemo.Infrastructure.csproj
│   └── Api/
│       └── CleanArchitectureDemo.Api.csproj
└── tests/

We will not use the tests folder in this lesson, but later lessons can place unit and integration test projects there. Keeping application source code under src separates it from tests and solution-level files.

1. Create the solution

Open a terminal in the directory where you want to create the solution. The following commands work with the .NET CLI on Windows, macOS, and Linux:

mkdir CleanArchitectureDemo
cd CleanArchitectureDemo

dotnet new sln -n CleanArchitectureDemo

When using the .NET 10 SDK, you should expect to see CleanArchitectureDemo.slnx. Older SDK versions may create a traditional .sln file instead. Both formats organize projects, but this lesson uses the .NET 10 default, .slnx. The official documentation also describes how to add projects and organize them into solution folders. ([learn.microsoft.com](https://learn.microsoft.com/dotnet/core/tools/dotnet-sln?utm_source=openai))

2. Create the layer projects

We will create class library projects for Domain, Application, and Infrastructure. The API will use the ASP.NET Core Web API template. All projects should target the same framework, net10.0.

mkdir src
mkdir src/Domain
mkdir src/Application
mkdir src/Infrastructure
mkdir src/Api

dotnet new classlib -n CleanArchitectureDemo.Domain -o src/Domain --framework net10.0
dotnet new classlib -n CleanArchitectureDemo.Application -o src/Application --framework net10.0
dotnet new classlib -n CleanArchitectureDemo.Infrastructure -o src/Infrastructure --framework net10.0
dotnet new webapi -n CleanArchitectureDemo.Api -o src/Api --framework net10.0 --use-controllers

Class library projects hold reusable code but do not start a web server by themselves. The API project uses the ASP.NET Core hosting model and exposes HTTP endpoints. We are choosing the controller-based template because later lessons will implement REST endpoints through controllers.

The templates may create sample files. For example, the API project can contain a sample controller or weather-related model. Those files are not part of our business application and can be removed after the initial setup. First, add the projects to the solution:

dotnet sln CleanArchitectureDemo.slnx add src/Domain/CleanArchitectureDemo.Domain.csproj --solution-folder src/Domain
dotnet sln CleanArchitectureDemo.slnx add src/Application/CleanArchitectureDemo.Application.csproj --solution-folder src/Application
dotnet sln CleanArchitectureDemo.slnx add src/Infrastructure/CleanArchitectureDemo.Infrastructure.csproj --solution-folder src/Infrastructure
dotnet sln CleanArchitectureDemo.slnx add src/Api/CleanArchitectureDemo.Api.csproj --solution-folder src/Api

dotnet sln CleanArchitectureDemo.slnx list

Solution folders are an IDE-level organizational feature. They can match the physical folders, which improves readability, but they are not the same thing as directories on disk.

3. Configure Clean Architecture dependencies

Creating the projects is only half of the work. The direction of the dependencies is what protects the architecture. Our dependency graph is:

ProjectMay referencePrimary responsibility
DomainNo application projectEntities, value objects, domain rules
ApplicationDomainUse cases, DTOs, abstractions, application services
InfrastructureApplication and, when required, DomainEF Core, repositories, external services, technical implementations
APIApplication and InfrastructureHTTP, controllers, dependency injection composition root

Add the references with the following commands:

dotnet reference add src/Domain/CleanArchitectureDemo.Domain.csproj --project src/Application/CleanArchitectureDemo.Application.csproj

dotnet reference add src/Application/CleanArchitectureDemo.Application.csproj --project src/Infrastructure/CleanArchitectureDemo.Infrastructure.csproj
dotnet reference add src/Domain/CleanArchitectureDemo.Domain.csproj --project src/Infrastructure/CleanArchitectureDemo.Infrastructure.csproj

dotnet reference add src/Application/CleanArchitectureDemo.Application.csproj --project src/Api/CleanArchitectureDemo.Api.csproj
dotnet reference add src/Infrastructure/CleanArchitectureDemo.Infrastructure.csproj --project src/Api/CleanArchitectureDemo.Api.csproj

In the .NET 10 SDK, dotnet reference add writes ProjectReference elements to the project file. These references create build dependencies and ensure that referenced projects are built first. ([learn.microsoft.com](https://learn.microsoft.com/dotnet/core/tools/dotnet-add-reference?utm_source=openai))

You can inspect the result with:

dotnet reference list --project src/Application/CleanArchitectureDemo.Application.csproj
dotnet reference list --project src/Infrastructure/CleanArchitectureDemo.Infrastructure.csproj
dotnet reference list --project src/Api/CleanArchitectureDemo.Api.csproj

The Domain project must not reference Infrastructure or API. Domain is the center of the architecture and should remain independent from database and framework details. The API reference to Infrastructure is acceptable because the API acts as the composition root, where concrete implementations will later be registered with the dependency injection container.

4. Establish the namespace convention

Using dots in project names makes namespaces predictable. A class in the Domain project can use the following namespace:

namespace CleanArchitectureDemo.Domain.Entities;

public sealed class Product
{
    public Guid Id { get; private set; }
    public string Name { get; private set; } = string.Empty;
}

Our namespace convention is:

  • CleanArchitectureDemo.Domain and its child namespaces contain domain code.
  • CleanArchitectureDemo.Application contains use cases, DTOs, and abstractions.
  • CleanArchitectureDemo.Infrastructure contains technical implementations.
  • CleanArchitectureDemo.Api contains controllers and API-specific code.

You may explicitly define the root namespace in each .csproj file:

<PropertyGroup>
  <TargetFramework>net10.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
  <RootNamespace>CleanArchitectureDemo.Domain</RootNamespace>
</PropertyGroup>

Use the corresponding project name for the other three projects. The templates usually infer the namespace from the project name, but explicitly documenting the convention makes large-team development more consistent.

5. Build and verify the solution

Although no real business code exists yet, we can validate the project graph:

dotnet restore
dotnet build CleanArchitectureDemo.slnx

A successful build confirms that the target frameworks, paths, and project references are valid. To run the API project:

dotnet run --project src/Api/CleanArchitectureDemo.Api.csproj

Open the local address shown in the terminal. If OpenAPI support is enabled by the template, you can also inspect the generated API documentation. The ASP.NET Core Web API template provides the basic hosting structure required to start building an API. ([learn.microsoft.com](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-10.0&utm_source=openai))

Common mistakes

Adding references in the wrong direction

A common mistake is allowing Domain to reference Infrastructure. This makes the business model depend on database or framework details. Instead, define an abstraction in Application and implement it in Infrastructure.

Adding every package to every project

Do not install Entity Framework Core, SQL Server, or FluentValidation in every project at the beginning. Add a package only to the project that uses it. EF Core and SQL Server packages will normally belong to Infrastructure, while API-specific OpenAPI packages belong to API.

Confusing namespaces with folders

Namespaces do not have to exactly match physical directories. However, inconsistent namespaces make a codebase difficult to understand. Establish a convention early and apply it consistently.

Forgetting to add a project to the solution

A project may exist on disk but still be missing from the solution. Always run dotnet sln list when you are unsure whether the project was added.

Practice exercise

Complete the following exercise:

  1. Create a solution named CleanArchitectureDemo.
  2. Create the four layer projects under src.
  3. Add the projects to solution folders named Domain, Application, Infrastructure, and Api.
  4. Configure the references according to the dependency graph shown above.
  5. Add a simple Product entity to the Domain project.
  6. Run dotnet build and confirm that the solution builds successfully.

As an additional design check, consider whether the API should reference Domain directly. It is technically possible, but routing application requests through Application keeps the API focused on transport concerns and reduces the exposure of domain details.

Conclusion

In this lesson, we created the .NET 10 solution, prepared the four core Clean Architecture projects, and defined the dependency direction. The most important point is that architecture is not created by folder names alone. It is enforced through project references, namespace conventions, and clear responsibilities.

In the next lesson, we will deepen the Domain layer by designing entities and value objects in the context of the real project. The dependency foundation created here will allow every later feature to be added in a controlled and maintainable way.

Sources