Skip to main content

Overview

Each service uses appsettings.json for configuration. These settings can be overridden by environment-specific files (appsettings.Development.json, appsettings.Production.json) or environment variables.

Configuration Structure by Service

Catalog API

File: Services/Catalog/Catalog.API/appsettings.json
{
  "ConnectionStrings": {
    "Database": "Server=localhost;Port=5432;Database=CatalogDb;User Id=postgres;Password=postgres;Include Error Detail=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
Configuration Details:
SectionKeyDescriptionDefault Value
ConnectionStringsDatabasePostgreSQL connection stringlocalhost:5432
LoggingDefaultDefault log levelInformation
LoggingMicrosoft.AspNetCoreASP.NET Core log levelWarning
-AllowedHostsCORS allowed hosts* (all)
Database: Uses Marten with PostgreSQL for document storage.

Basket API

File: Services/Basket/Basket.API/appsettings.json
{
  "ConnectionStrings": {
    "Database": "Server=localhost;Port=5433;Database=BasketDb;User Id=postgres;Password=postgres;Include Error Detail=true",
    "Redis": "localhost:6379"
  },
  "GrpcSettings": {
    "DiscountUrl": "https://localhost:5052"
  },
  "MessageBroker": {
    "Host": "amqp://localhost:5672",
    "UserName": "guest",
    "Password": "guest"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
Configuration Details:
SectionKeyDescriptionDefault Value
ConnectionStringsDatabasePostgreSQL connection stringlocalhost:5433
ConnectionStringsRedisRedis cache connectionlocalhost:6379
GrpcSettingsDiscountUrlDiscount gRPC service URLhttps://localhost:5052
MessageBrokerHostRabbitMQ host addressamqp://localhost:5672
MessageBrokerUserNameRabbitMQ usernameguest
MessageBrokerPasswordRabbitMQ passwordguest
Features:
  • PostgreSQL for cart persistence
  • Redis for distributed caching
  • gRPC client for discount service
  • MassTransit with RabbitMQ for event publishing

Discount gRPC

File: Services/Discount/Discount.Grpc/appsettings.json
{
  "ConnectionStrings": {
    "Database": "Data Source=discountdb"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Information"
    }
  },
  "AllowedHosts": "*",
  "Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http2"
    }
  }
}
Configuration Details:
SectionKeyDescriptionDefault Value
ConnectionStringsDatabaseSQLite database filediscountdb
KestrelProtocolsHTTP protocol versionHttp2 (gRPC)
LoggingDefaultDefault log levelInformation
LoggingMicrosoft.AspNetCoreASP.NET Core log levelInformation
Important: The Kestrel.EndpointDefaults.Protocols is set to Http2 to enable gRPC communication. Database: Uses Entity Framework Core with SQLite for lightweight discount storage.

Ordering API

File: Services/Ordering/Ordering.API/appsettings.json
{
  "ConnectionStrings": {
    "Database": "Server=localhost;Database=OrderDb;User Id=sa;Password=SwN12345678;Encrypt=False;TrustServerCertificate=True"
  },
  "MessageBroker": {
    "Host": "amqp://localhost:5672",
    "UserName": "guest",
    "Password": "guest"
  },
  "FeatureManagement": {
    "OrderFullfilment": false
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
Configuration Details:
SectionKeyDescriptionDefault Value
ConnectionStringsDatabaseSQL Server connection stringlocalhost:1433
MessageBrokerHostRabbitMQ host addressamqp://localhost:5672
MessageBrokerUserNameRabbitMQ usernameguest
MessageBrokerPasswordRabbitMQ passwordguest
FeatureManagementOrderFullfilmentFeature flag for order fulfillmentfalse
Features:
  • SQL Server with Entity Framework Core
  • MassTransit with RabbitMQ for consuming basket checkout events
  • Feature flags for controlling order fulfillment workflow
Connection String Options:
  • Encrypt=False: Disables SSL encryption (dev only)
  • TrustServerCertificate=True: Bypasses certificate validation (dev only)

YARP API Gateway

File: ApiGateways/YarpApiGateway/appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ReverseProxy": {
    "Routes": {
      "catalog-route": {
        "ClusterId": "catalog-cluster",
        "Match": {
          "Path": "/catalog-service/{**catch-all}"
        },
        "Transforms": [{ "PathPattern": "{**catch-all}" }]
      },
      "basket-route": {
        "ClusterId": "basket-cluster",
        "Match": {
          "Path": "/basket-service/{**catch-all}"
        },
        "Transforms": [{ "PathPattern": "{**catch-all}" }]
      },
      "ordering-route": {
        "ClusterId": "ordering-cluster",
        "RateLimiterPolicy": "fixed",
        "Match": {
          "Path": "/ordering-service/{**catch-all}"
        },
        "Transforms": [{ "PathPattern": "{**catch-all}" }]
      }
    },
    "Clusters": {
      "catalog-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "http://catalog.api:8080"
          }
        }
      },
      "basket-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "http://basket.api:8080"
          }
        }
      },
      "ordering-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "http://ordering.api:8080"
          }
        }
      }
    }
  }
}
Reverse Proxy Routes:
RoutePath PatternBackend ServiceRate Limiting
catalog-route/catalog-service/*http://catalog.api:8080No
basket-route/basket-service/*http://basket.api:8080No
ordering-route/ordering-service/*http://ordering.api:8080Yes (fixed window)
Rate Limiting Configuration (in Program.cs):
  • Policy: Fixed Window
  • Window: 10 seconds
  • Permit Limit: 5 requests per window
Path Transforms:
  • Incoming: /catalog-service/products
  • Transformed: /products (service receives without prefix)
Local Development (appsettings.Local.json):
"catalog-cluster": {
  "Destinations": {
    "destination1": {
      "Address": "http://localhost:6000/"
    }
  }
}
For local development, clusters point to localhost ports instead of Docker service names.

Shopping Web

File: WebApps/Shopping.Web/appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ApiSettings": {
    "GatewayAddress": "https://localhost:6064"
  }
}
Configuration Details:
SectionKeyDescriptionDefault Value
ApiSettingsGatewayAddressYARP Gateway base URLhttps://localhost:6064
API Clients:
  • Uses Refit for HTTP client generation
  • All services accessed through the gateway
  • Service endpoints:
    • Catalog: {GatewayAddress}/catalog-service
    • Basket: {GatewayAddress}/basket-service
    • Ordering: {GatewayAddress}/ordering-service

Common Configuration Sections

Logging

All services use standard ASP.NET Core logging configuration:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}
Log Levels: Trace, Debug, Information, Warning, Error, Critical, None

AllowedHosts

{
  "AllowedHosts": "*"
}
Controls host header filtering. Use specific domains in production.

Environment-Specific Configuration

Development Settings

Minimal overrides in appsettings.Development.json:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

Docker Settings

In Docker environments, settings are primarily controlled via environment variables in docker-compose.override.yml rather than separate appsettings files.

Configuration Best Practices

Store sensitive data in User Secrets during development:
dotnet user-secrets set "ConnectionStrings:Database" "your-connection-string"
Override sensitive settings using environment variables:
export ConnectionStrings__Database="production-connection-string"
Note: Use double underscores (__) to represent nested JSON levels.
For production, consider using Azure App Configuration or Azure Key Vault:
builder.Configuration.AddAzureAppConfiguration(options =>
{
    options.Connect(connectionString)
           .ConfigureKeyVault(kv => kv.SetCredential(credential));
});
Use the FeatureManagement section for feature toggles:
{
  "FeatureManagement": {
    "OrderFullfilment": true,
    "NewCheckoutFlow": false
  }
}

Reading Configuration in Code

Strongly-Typed Configuration

// Configuration class
public class MessageBrokerSettings
{
    public string Host { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
}

// Registration
builder.Services.Configure<MessageBrokerSettings>(
    builder.Configuration.GetSection("MessageBroker"));

// Usage
public class MyService
{
    private readonly MessageBrokerSettings _settings;
    
    public MyService(IOptions<MessageBrokerSettings> options)
    {
        _settings = options.Value;
    }
}

Direct Access

var database = builder.Configuration.GetConnectionString("Database");
var discountUrl = builder.Configuration["GrpcSettings:DiscountUrl"];

Connection String Formats

PostgreSQL

Server={host};Port={port};Database={db};User Id={user};Password={pwd};Include Error Detail=true

SQL Server

Server={host};Database={db};User Id={user};Password={pwd};Encrypt=False;TrustServerCertificate=True

SQLite

Data Source={filename}

Redis

{host}:{port}

RabbitMQ

amqp://{host}:{port}

Build docs developers (and LLMs) love