Configuration
Requirements: Dapr 1.18+ with mTLS enabled. .NET 10.0 SDK.
Virtufin.API supports configuration via environment variables and command-line arguments. Both methods are supported with consistent behavior across all Virtufin projects.
Precedence
Configuration is loaded in the following order:
- Environment variables (loaded first)
- Command-line arguments (loaded second)
Command-line arguments take precedence over environment variables.
Configuration Keys
Port Configuration
| Key | Description | Default |
|---|---|---|
HttpPort |
HTTP port (REST, Swagger, health, gRPC-Web) | 5001 |
GrpcPort |
gRPC port (native gRPC HTTP/2 h2c) | 5002 |
DaprHttpPort |
Dapr HTTP port | 3500 |
DaprGrpcPort |
Dapr gRPC port | 50001 |
Environment Variables
Set configuration using environment variables:
export HttpPort=5001
export GrpcPort=5002
export DaprHttpPort=3500
export DaprGrpcPort=50001
export DAPR_RETRY_ATTEMPTS=3
export DAPR_RETRY_BASE_DELAY_MS=200
export DAPR_CIRCUIT_BREAKER_THRESHOLD=5
export DAPR_CIRCUIT_BREAKER_DURATION_SECONDS=30
Dapr Resiliency
The DaprResiliencePipeline wraps every Dapr SDK call the API
makes, including the Gateway.Invoke and Gateway.InvokeJson gRPC
calls to downstream services (WebSocketManager, WorkManager). The
pipeline uses Polly: retry with exponential backoff, then circuit
breaker. The circuit state is exposed at /health (tag dapr).
| Key | Description | Default | Range |
|---|---|---|---|
DAPR_RETRY_ATTEMPTS |
Max retry attempts per Dapr call before the pipeline throws. | 3 |
0–20 |
DAPR_RETRY_BASE_DELAY_MS |
Base delay between attempts; actual delay is RetryBaseDelayMs * 2^attempt. |
200 |
10–60000 |
DAPR_CIRCUIT_BREAKER_THRESHOLD |
Minimum throughput before the circuit can trip (Polly MinimumThroughput). |
5 |
1–1000 |
DAPR_CIRCUIT_BREAKER_DURATION_SECONDS |
How long the circuit stays open before transitioning to half-open. | 30 |
1–3600 |
The circuit breaker uses Polly's FailureRatio = 0.5 (a 50% failure
rate trips the circuit). The above env vars control the other knobs.
Command-Line Arguments
Pass arguments when running the application:
Virtufin.Api --http-port 5001 --grpc-port 5002
Available Arguments
| Argument | Description | Default |
|---|---|---|
--http-port <port> |
HTTP port (REST, Swagger, health, gRPC-Web) | 5001 |
--grpc-port <port> |
gRPC port (native gRPC HTTP/2 h2c) | 5002 |
--dapr-http-port <port> |
Dapr HTTP port | 3500 |
--dapr-grpc-port <port> |
Dapr gRPC port | 50001 |
Note: The HTTP port serves REST, Swagger, health probes, and gRPC-Web over HTTP/1.1. The gRPC port serves native gRPC over HTTP/2 cleartext (h2c).
Examples
Using Environment Variables
export HttpPort=3000
export GrpcPort=3002
./Virtufin.Api
Using Command-Line Arguments
./Virtufin.Api --http-port 3000 --grpc-port 3002
Combining Both
Environment variables set defaults, command-line arguments override:
export HttpPort=3000
./Virtufin.Api --grpc-port 3002
In this example, HttpPort is 3000 (from environment) and GrpcPort is 3002 (from command line).
CORS Configuration
The API supports CORS configuration via the Cors:AllowedOrigins configuration key:
export Cors:AllowedOrigins__0=https://example.com
export Cors:AllowedOrigins__1=https://app.example.com
Or via appsettings.json:
{
"Cors": {
"AllowedOrigins": ["https://example.com", "https://app.example.com"]
}
}
If no origins are configured, CORS is disabled and all cross-origin requests are rejected.