less than 1 minute read

The options pattern uses classes to provide strongly typed access to configuration values, including environment variables.

Environment variables can be hierarchical. They use __ as separator.

CoreConfig__GlobalId
ServiceBusConfig__ConnectionString
GrpcConfig__RemoteHostAddress

We can use map section.

services.Configure<CoreConfig>(config.GetSection(nameof(CoreConfig)))

Or access it directly. You can see that you have to use : as separator.

config.GetValue<string>("ServiceBusConfig:ConnectionString")

Tags:

Updated:

Comments