Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
One of the aspects I love about .NET Core is the new configuration and options pattern. In a continuation from my last post on using AWS Parameter Store for Data Protection keys, you can imagine it is possible to use Parameter Store for .NET Core Configuration.
There is a package by AWS that facilitates making using Parameter Store incredibly easy. Simply add the Amazon.Extensions.Configuration.SystemsManager package to your project and use the AddSystemsManager extension method on IConfigurationBuilder
The argument you pass to AddSystemsManager will be the prefix to your configuration hierarchy within Parameter Store. In my example, I’m using /Demo as my prefix, as you will also see below.
If you look at the first two entries, I can now create classes that match this hierarchy.
Next step is to add this configuration via the IServiceCollection using the Configure<T> method. Where T is our configuration type DemoConfig
This will add registration for the type IOptions<DemoConfig> so we can inject it in our Controllers or anywhere else the ServiceProvider is used.
This results in our config variable being set to the values from Parameter Store.
Parameter Store for .NET Core
If you have any questions or comments, please let me know on twitter as I will focus my posts on those questions and comments.