Skip to content

Step 01 — Create the project ​

What you'll do: create a .NET 10 solution with an empty Orders API, and start PostgreSQL and RabbitMQ in Docker.

By the end of the guide you will have built this (today you start with the Orders.Api box and the containers):

Architecture: a client calls Orders.Api, which saves orders and outbox rows in one transaction in the orders database; its OutboxPublisher publishes to the RabbitMQ orders exchange; the shipping.order-placed queue delivers to Shipping.Worker, which saves inbox rows and shipments in the shipping database; both services send traces and logs to the Aspire dashboard

Steps ​

  1. Install the tools.

    ToolVersionWhy
    .NET SDK10.0builds and runs the apps
    Docker Desktop (or another Docker engine)any recentruns PostgreSQL and RabbitMQ
    curlanycalls the API
  2. Create the folder, pin the SDK and create the solution. The .slnx format is the new, short XML solution file that .NET 10 uses by default.

    bash
    mkdir outbox-inbox-pattern-guide && cd outbox-inbox-pattern-guide
    dotnet new globaljson --sdk-version 10.0.401 --roll-forward latestFeature
    dotnet new gitignore
    dotnet new sln --name OutboxInbox --format slnx
    dotnet new web -o src/Orders.Api -n Orders.Api
    dotnet sln OutboxInbox.slnx add src/Orders.Api/Orders.Api.csproj

    global.json pins the SDK so everyone on the team builds with the same compiler. rollForward: latestFeature still accepts newer 10.0 feature bands.

  3. Move the settings every project shares into Directory.Build.props at the root. MSBuild picks this file up for every project below it, so each .csproj stays almost empty.

    xml
    <PropertyGroup>
      <TargetFramework>net10.0</TargetFramework>
      <LangVersion>latest</LangVersion>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    Delete the same four properties from Orders.Api.csproj; only the <Project Sdk="Microsoft.NET.Sdk.Web"> element is left.

  4. Give the API a fixed port. In launchSettings.json set the http profile to http://localhost:5080 (and the https profile to https://localhost:7080), and set launchBrowser to false: this is an API, not a web page.

  5. Replace Program.cs with a root endpoint that names the service:

    csharp
    var builder = WebApplication.CreateBuilder(args);
    
    var app = builder.Build();
    
    if (!app.Environment.IsDevelopment())
    {
        app.UseHsts();
        app.UseHttpsRedirection();
    }
    
    app.MapGet("/", () => TypedResults.Ok(new { service = "Orders.Api" }));
    
    app.Run();

    Outside Development the API forces HTTPS. Locally you call it over plain HTTP to keep the curl commands short.

  6. Add the containers. docker-compose.yml starts one PostgreSQL and one RabbitMQ, with pinned image tags and health checks:

    yaml
    services:
      postgres:
        image: postgres:17.12-alpine
        environment:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres # local development password, not a secret
        ports:
          - "5433:5432" # 5433 on the host, so it never clashes with a PostgreSQL you already run on 5432
        volumes:
          - postgres-data:/var/lib/postgresql/data
          - ./docker/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U postgres -d shipping"]
    
      rabbitmq:
        image: rabbitmq:4.4.1-management
        ports:
          - "5672:5672"   # AMQP, used by the apps
          - "15672:15672" # management UI
        healthcheck:
          test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]

    docker/postgres/init.sql runs the first time the volume is created and makes two databases, orders and shipping:

    sql
    CREATE DATABASE orders;
    CREATE DATABASE shipping;
  7. Start everything:

    bash
    docker compose up -d --wait
    dotnet run --project src/Orders.Api

Check it works ​

bash
dotnet build OutboxInbox.slnx -warnaserror

You should see 0 Warning(s) and 0 Error(s).

bash
curl -i http://localhost:5080/
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{"service":"Orders.Api"}

Check that both databases exist:

bash
docker compose exec postgres psql -U postgres -tAc "select datname from pg_database where datname in ('orders','shipping')"
orders
shipping

Open the RabbitMQ management UI at http://localhost:15672 and sign in with guest / guest. These are the image's local defaults; never use them on a server.

Stop the API with Ctrl+C. Leave the containers running for the next step, or stop them with docker compose down (add -v to delete the data too).

Why it works ​

Two services, two databases. The guide builds an Orders API and, later, a Shipping worker. Each one owns its data. Running both databases in one PostgreSQL container keeps the laptop light, but the apps never share tables. That rule matters later: the only way Shipping learns about an order is through a message.

Port 5433. Inside the container PostgreSQL listens on its usual port 5432. Compose publishes it on port 5433 of your machine, because many developers already run a local PostgreSQL on 5432, and the apps would silently connect to the wrong server (you would see role "postgres" does not exist).

Pinned tags and health checks. postgres:17.12-alpine and rabbitmq:4.4.1-management name an exact patch, so the guide works the same next year. A health check is a command Docker runs inside the container to decide when it is ready. docker compose up --wait blocks until both report healthy, so the app never starts against a database that is still booting.

RabbitMQ is a message broker: a server that accepts messages from one program and hands them to others. The -management image adds the web UI on port 15672, which you will use to watch messages move.

Typed results. TypedResults.Ok(...) returns a strongly typed Ok<T> instead of a plain object. The compiler and OpenAPI tools can see exactly what each endpoint returns.

MIT licensed. Every step is a commit: git checkout step-01.