Skip to content

Consider merging Microsoft.Extensions.Options.DataAnnotations into Microsoft.Extensions.Options #82844

Open

Description

@eerhardt

The Microsoft.Extensions.Options.DataAnnotations library only exists because it has a dependency on System.ComponentModel.Annotations. Since System.ComponentModel.Annotations wasn't in netstandard2.0 by default, the code in this library was split into its own package instead of being added to Microsoft.Extensions.Options.

However, recently we've added a dependency from Microsoft.Extensions.Options netstandard2.0 to System.ComponentModel.Annotations in the 6.0.0-preview5.21301.5 NuGet package. It looks like this was added by a combination of #52084 + #35606.

Also, as of 6.0, System.ComponentModel.Annotations is now part of the netX.0+ TFM by default. It is no longer a separate NuGet package.

With #82749, we are doubling down on this dependency, and fully adding System.ComponentModel.Annotations code to Microsoft.Extensions.Options.

Given all these changes, it doesn't make sense to keep Microsoft.Extensions.Options.DataAnnotations as a separate library/NuGet package. It is just an extra package, assembly, etc and can be merged into Microsoft.Extensions.Options.

I'm not exactly sure how to do this with NuGet packages. I know we will need TypeForwardedTo attributes in order to keep back compat working. Does that mean we will need to keep shipping a NuGet package for Microsoft.Extensions.Options.DataAnnotations with just the TypeForwardedTo attribute? Maybe we only need to ship 1 more - 8.0.0 with TypeForwardedTo and then it can be dead-ended after that?

cc @tarekgh @ericstj @ViktorHofer

Activity

  1. ghost added
    untriaged
    on Mar 1, 2023
  2. added this to the 8.0.0 milestone on Mar 1, 2023
  3. self-assigned this
    on Mar 1, 2023
  4. removed
    untriaged
    on Mar 1, 2023
  5. ericstj commented on Mar 1, 2023

    @ericstj
    Member

    This sounds reasonable. Is there any urgency here or is this just about cleaning things up? (trying to understand if merging them will enable any scenarios)

  6. tarekgh commented on Mar 1, 2023

    @tarekgh
    Member

    My understanding there is no urgency. This mostly optimizes loading one assembly instead of two in the apps.

  7. eerhardt commented on Mar 2, 2023

    @eerhardt
    MemberAuthor

    Is there any urgency here or is this just about cleaning things up? (trying to understand if merging them will enable any scenarios)

    My understanding there is no urgency. This mostly optimizes loading one assembly instead of two in the apps.

    Agreed. This is more of a "clean up" thing, and isn't blocking any scenarios.

  8. modified the milestones: 8.0.0, 9.0.0 on Jul 25, 2023
  9. tarekgh commented on Jul 25, 2023

    @tarekgh
    Member

    I talked offline with @ericstj and we believe this better be done in the early cycle of the next release and there will be some risk doing it now.

  10. modified the milestones: 9.0.0, Future on Nov 18, 2023
  11. alrz commented on Oct 30, 2024

    @alrz
    Member

    As part of this I'd like to bring up an issue when validation fails, which probably needs this two packages be tightly coupled,

    DataAnnotation validation failed for '<type>' members: '<property-name>'

    When using [ConfigurationKeyName], that name/path should appear in the exception, as the <property-name> isn't quite helpful.

  12. tarekgh commented on Oct 30, 2024

    @tarekgh
    Member

    @alrz could you please provide a small reproduce project for the issue?

  13. alrz commented on Oct 30, 2024

    @alrz
    Member

    When [ConfigurationKeyName] is used in conjunction with annotations, only the property name is mentioned in the exception, not the path:

    public class ConfigurationRoot
    {
        [Required]
        [ConfigurationKeyName("OTEL_SERVICE_NAME")]
        public string ServiceName {get; init;}
    }

    If the service name is not set, an exception is raised DataAnnotation validation failed for 'ConfigurationRoot' members: 'ServiceName' . That doesn't say anything about the configuration name to be set.

  14. rosebyte commented on Mar 17, 2026

    @rosebyte
    Member

    Triage: we may consider it when we will have capacity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions