Secret Manager keeps local-development values out of project configuration files. Initialize it from the project directory; the resulting UserSecretsId can be checked in because it identifies a secret file stored on the developer’s machine. section 9.4.2
Listing 9.13 Adds the connection string to Secret Manager for ManningBooksApi project
dotnet user-secrets set "ConnectionStrings:Catalog" "DataSource=manningbooks.db;cache=shared"
Set a named connection string in Secret Manager with the .NET CLI. section 9.4.2
Listing 9.14 Getting connection string from secret through configuration
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration; #1
builder.Services.AddDbContext<CatalogContext>(options =>
{
var connStr = config.GetConnectionString("Catalog"); #2
options.UseSqlite(connStr);
});
Read the stored connection string through application configuration when registering the database context. section 9.4.2
Secret Manager also supports values that vary by developer or environment:
- Store Azure AD client and tenant IDs as user secrets instead of putting them in appsettings.json. section 9.5.2
- Treat local user secrets as a development convenience, not a general production secret store; production options depend on the hosting environment. section 9.4.2





