Skip to content

State Native Framework way for validation #3

Description

@DanielHabenicht

Hey, I used your Package extensively and it was a pleasure!

Recently we migrated to Dotnet 8 which brings a native way of validating the configuration:

builder.Services.AddOptions<AppSettingsRootConfiguration>()
    .BindConfiguration("")
    .ValidateDataAnnotations()
    .ValidateOnStart();

With Data Annotation on the RootConfiguration:

 public class AppSettingsRootConfiguration
    {
        /// <summary>
        /// The Main Configuration.
        /// </summary>
        /// <value>The configuration.</value>
        [Required]
        [ValidateObjectMembers]
        public AppConfig ExampleToolConfiguration { get; set; }

        [Required]
        [ValidateEnumeratedItems]
        public List<ComplexObject> ExampleList { get; set; }
    }

I just wanted to share and thought adding this to the README might be a good place to promote the native way.

Be aware we came across a bug for Dictionaries: dotnet/runtime#97873

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions