Overview
RealtimeChat uses ASP.NET Core’s configuration system with environment-specific settings files. Configuration is managed throughappsettings.json files, environment variables, and user secrets.
Configuration Files
The application uses three main configuration files:- appsettings.json
- appsettings.Development.json
- appsettings.Docker.json
Base configuration for all environments:
Configuration Structure
Database Connection
The connection string is configured underConnectionStrings:DefaultConnectionString:
Connection String Parameters
| Parameter | Description | Example |
|---|---|---|
Server | PostgreSQL host | localhost, host.docker.internal, db.example.com |
Port | PostgreSQL port | 5432 |
Username | Database user | postgres, admin |
Password | Database password | postgres, secure_password |
Database | Database name | realtime_chat_db |
Include Error Detail | Show detailed errors | true (dev only) |
MaxPoolSize | Maximum connections | 10 (production) |
MinPoolSize | Minimum connections | 2 (production) |
CORS Configuration
CORS is configured via theAllowCorsAddress setting:
Logging Configuration
ASP.NET Core logging is configured under theLogging section:
Log Levels
Trace
Trace
Most detailed logs. Use for development debugging only.
Debug
Debug
Detailed information for debugging.
Information
Information
General informational messages (recommended for development).
Warning
Warning
Warning messages for unexpected events.
Error
Error
Error messages (recommended for production).
Critical
Critical
Critical failures requiring immediate attention.
Authentication Settings
The application uses ASP.NET Core Identity with cookie-based authentication:- Password requirements (configurable)
- Cookie expiration
- Lockout policies
- Token providers
Database Context Configuration
The database context is configured inServiceCollectionExtensions.cs:
In development mode, the context enables sensitive data logging and detailed errors for easier debugging.
Environment Variables
All configuration can be overridden using environment variables with the following syntax:Use double underscores (
__) to represent nested configuration keys in environment variables.Docker Environment Variables
When running in Docker, configure via docker-compose.yml:User Secrets (Development)
For local development, use User Secrets to store sensitive data:GraphQL Configuration
The application uses Hot Chocolate for GraphQL:/graphql- GraphQL endpoint/graphql/playground- Interactive GraphQL IDE (development only)
Environment-Specific Behavior
Development Mode
WhenASPNETCORE_ENVIRONMENT=Development:
- Detailed error pages
- Sensitive data logging enabled
- GraphQL playground available
- Swagger/OpenAPI endpoints exposed (if configured)
- Console logging with detailed EF Core queries
Production Mode
WhenASPNETCORE_ENVIRONMENT=Production:
- Generic error pages
- Minimal logging
- No sensitive data in logs
- GraphQL playground disabled
- Connection pooling enforced
Docker Mode
WhenASPNETCORE_ENVIRONMENT=Docker:
- Uses
host.docker.internalfor database connection - Configured for container networking
- Production-like security settings
Configuration Best Practices
Use Environment Variables in Production
Override configuration with environment variables instead of modifying config files:
Separate Dev and Prod Configs
Keep development and production configurations completely separate:
appsettings.Development.json- Local developmentappsettings.Docker.json- Docker containers- Environment variables - Production deployment
Configuration Precedence
ASP.NET Core loads configuration in the following order (later sources override earlier ones):appsettings.jsonappsettings.{Environment}.json- User Secrets (Development only)
- Environment variables
- Command-line arguments
This means environment variables will always override settings in
appsettings.json files.Troubleshooting
Configuration value not being read
Configuration value not being read
Check the configuration precedence order. Environment variables may be overriding your
appsettings.json values.Debug by inspecting the configuration at runtime:CORS errors in browser
CORS errors in browser
Verify the Ensure there’s no trailing slash and the protocol (http/https) matches.
AllowCorsAddress setting matches your frontend origin exactly:Database connection fails
Database connection fails
Test the connection string format:Common issues:
- Wrong host (localhost vs 127.0.0.1 vs host.docker.internal)
- Firewall blocking port 5432
- Incorrect credentials
- Database doesn’t exist
Next Steps
- Database Setup - Configure PostgreSQL and migrations
- Docker Deployment - Deploy with Docker
- API Reference - Explore GraphQL API