Core vs Framework
Framework is legacy implementation of .NET which was could run only on windows, hosted on IIS. Core is a complete rewrite implementation with modularity that can run on cross platforms using built in Kestrel which makes the apps faster. Core has built in way to manage configuration, dependency Injection middlewares centrally while in framework it was scattered and manually done
Explain .NET Core Architecture
Kestrel vs IIS
Kestrel is default built in to .net core which is a lightweight fast web server that can run on cross platforms. But not production grade because is lacks lot of platform specific features.
IIS is a complete web server with features like app pool recycle, port management, ssl certificate. It is used as reverse proxy in production in front of Kestrel to add in these features and Kestrel only does traffic management
Web.config vs Appsettings.json
Web config was in framework written in XML and inconvenient to handle for different environments. The configuration usage in code was scattered with hardcoding of keys. Application needed to be restart to apply changes to configuration
Appsettings is a better readable json in core which is picked by automatically by configuration service giving centralised management , DI support, validation, hot reload and change tracking
Launchsettings vs Appsettings
Launchsettings is a tooling file that is used by CLI to know how to start the app. It is not used for publishing the apps. It can create profiles with application url, whether to launch browser, ports, add environment Variables which is ultimately read by configuration service. It is found in properties folder.
Appsettings is the app config provider that configuration service reads and is used for publishing the app.
Does configuration service read launch settings
No. However launch settings can add environment Variables in locally run machine which the configuration service reads for localhost site.
What are launch profiles
How does core read config values
Configuration service reads multiple default and custom providers to merge into key value pairs. The later provider values override the earlier. It gives centralised way to manage with DI support and hot reload. We can mock and test.
With options pattern we get strongly typed, validation, change tracking, per request values
How to access values from configuration
Ad hoc way using builder.Configuration or bind it to classes making it strongly typed. Recommended way is to use options pattern
Ad hoc vs Binding config
Ad hoc is best for quick one off for simple primitive values and binding is good for reusing with complex nested sections like dictionary, list with strong typing.
Ad hoc converts the values and can throw exceptions while binding creates instances with default or null and then overwrite by extracting values, so can cause silent failures.
Ad hoc is hard to test because they are scattered but binding makes mock testing easier
What is options pattern
Pattern built in to read and manage grouped configuration settings with DI Support. It provides centralized configuration, strongly typed safe access using validations, hot reload and change tracking
IOptions, IOptionsSnapshot, IOptionsMonitor
IOptions is used for singleton snapshot of config at app start for stable and static values. It doesn’t support hot reload. Use it for api key, title, page secret, connection strings
IOptionsSnapshot is used for per request values. It is scoped + named options and refreshes at start of request. Use it for fresh request discount prices
IOptionsMonitor is used for values that can change manually or dynamically. It is singleton and supports hot reload + change tracking. Use it for disabling product category, flash sale discount, feature flags, alerts, cache levels, log levels
Why not getting binded
Class needs to be public non abstract with default parameterless constructor, public setter properties, not fields
The key might be missing
What if key is in lowercase
Binding is case insensitive
Why array values missing
When same key in different providers, the array is replaced, not merging of values
Mechanism of logging
Logging Providers
Log Levels