Using Secret Manager tool to store connection strings

It is a bad idea to keep passwords & connection strings in the source code.
So to make password & connection string management easier, Microsoft came up with Secret manager tool.

The Secret Manager tool provides a more general mechanism to store sensitive data for development work outside of your project tree. The Secret Manager tool is a project tool that can be used to store secrets for a .NET Core project during development. With the Secret Manager tool you can associate app secrets with a specific project and share them across multiple projects.

It is pretty handy when working on open source project.
I use secret manager tool to store client id/secret for third party authentication services and connection strings.

This short post shows how to use Secret manager tool to store connection strings:

From the command line just run command:

1
dotnet user-secrets set ConnectionStrings:DefaultConnection "<ConnectionString>"

In the application connection string can be read as usual:

1
Configuration.GetConnectionString("DefaultConnection")

More information about Secret manager tool can be found here: Safe storage of app secrets with the Secret Manager tool