.NET Core Production Best Practices
Apply production-grade best practices for .NET Core applications — configuration management, resilience patterns, and operational excellence.
Configuration & Resilience
- Configuration Hierarchy: appsettings.json → appsettings.{env}.json → environment variables → user secrets → Key Vault. Later sources override earlier ones
- Options Pattern: Bind configuration sections to strongly-typed classes — IOptions<T> (singleton), IOptionsSnapshot<T> (scoped, reloads on change), IOptionsMonitor<T> (real-time updates)
- Resilience (Polly): Retry with exponential backoff, circuit breaker, timeout, bulkhead isolation — Microsoft.Extensions.Http.Resilience integrates with HttpClientFactory
- HttpClientFactory: Create and manage HttpClient instances — connection pooling, DNS rotation, Polly integration. Never new HttpClient() directly
- Background Tasks: Use IHostedService for startup initialization, BackgroundService for continuous processing, IHostedLifecycleService for lifecycle hooks
- Feature Flags: Use Microsoft.FeatureManagement — toggle features without deployment. Percentage rollout, time-window flags, targeting filters
Try It Yourself: API Builder
Line 26: Unknown tag <list> on line 26
💡 "<list>" is not a valid HTML5 element. Use <div>, <span>, <p>, <section>, etc.
Line 29: Unknown tag <actionresult> on line 29
💡 "<actionresult>" is not a valid HTML5 element. Use <div>, <span>, <p>, <section>, etc.
Line 36: Unknown tag <actionresult> on line 36
💡 "<actionresult>" is not a valid HTML5 element. Use <div>, <span>, <p>, <section>, etc.
Line 43: Unknown tag <actionresult> on line 43
💡 "<actionresult>" is not a valid HTML5 element. Use <div>, <span>, <p>, <section>, etc.
Line 54: Wrong closing tag: </script> found, expected </actionresult> (line 54)
💡 Close <actionresult> (opened on line 43) with </actionresult> before closing </script>.
Line 54: Wrong closing tag: </body> found, expected </actionresult> (line 54)
💡 Close <actionresult> (opened on line 43) with </actionresult> before closing </body>.
Line 54: Wrong closing tag: </html> found, expected </actionresult> (line 54)
💡 Close <actionresult> (opened on line 43) with </actionresult> before closing </html>.
Line 2: Unclosed <html> (opened on line 2)
💡 Add </html> to properly close this element.
Line 9: Unclosed <body> (opened on line 9)
💡 Add </body> to properly close this element.
Line 16: Unclosed <script> (opened on line 16)
💡 Add </script> to properly close this element.
Line 26: Unclosed <list> (opened on line 26)
💡 Add </list> to properly close this element.
Line 29: Unclosed <actionresult> (opened on line 29)
💡 Add </actionresult> to properly close this element.
Line 36: Unclosed <actionresult> (opened on line 36)
💡 Add </actionresult> to properly close this element.
Line 43: Unclosed <actionresult> (opened on line 43)
💡 Add </actionresult> to properly close this element.