Skip to content

[API Proposal]: Add parameter-less and reflection-less AddUserSecrets via source generator #116202

Closed as not planned
@kzu

Description

@kzu

Background and motivation

Currently, AddUserSecrets relies on doing reflection to read the assembly-level attribute emitted via MSBuild.

This makes the consuming API less intuitive, since you have to pass either a type (which one? what for? not obvious) or an assembly (leaky implementation detail).

The user secrets ID property could be made visible to the compiler and a source generator could emit a parameterless AddUserSecrets that already had the right string in place.

API Proposal

namespace Microsoft.Extensions.Configuration;

    public static class UserSecretsConfigurationExtensions
    {
        public static IConfigurationBuilder AddUserSecrets(this IConfigurationBuilder configuration)
            where T : class
            => configuration.AddUserSecrets("[$(UserSecretsId) via MSBuild])", optional: true, reloadOnChange: false);

API Usage

configuration.AddUserSecrets();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions