adding-validation-to-strongly-typed-configuration-objects-in-dotnet-6/ #47
Replies: 7 comments 9 replies
-
This would work fine in cases where DataAnnotations were being used. Do you have any idea how do the same (preferably with equal simplicity) in case of FluentValidations? |
Beta Was this translation helpful? Give feedback.
-
I've been doing something very similar for a long time. I use these extension methods below to simplify this boilerplate which may help someone: |
Beta Was this translation helpful? Give feedback.
-
Thanks for a great article, as always. I would just warn readers that this approach doesn't support nested appsettings structure - dotnet/runtime#36093 |
Beta Was this translation helpful? Give feedback.
-
In a .NET 6 console app, how would this work under the
|
Beta Was this translation helpful? Give feedback.
-
Hi Andrew, this looks great. However I cannot resolve ValidateDataAnnotations(), I have installed the nuget package Microsoft.Extensions.DependencyInjection (7.0.0) I have the ValidateOnStart() method which is confusing |
Beta Was this translation helpful? Give feedback.
-
thank you for this great post andrew. i could not figure out how to get it to work until i saw the one thing i am noticing is that it will only validate top-level properties. i created an so it looks something like this public class AppSettings
{
[Required]
public string TopLevel { get; init; }
[Required]
public NestedSettings { get; init; }
...
}
public class NestedSettings
{
[Required]
public string Nested { get; init; }
...
} the nested settings are binded properly and accessible through injecting so two questions:
|
Beta Was this translation helpful? Give feedback.
-
This post so wonderfully explains the pattern. The validation part is just so goood... |
Beta Was this translation helpful? Give feedback.
-
adding-validation-to-strongly-typed-configuration-objects-in-dotnet-6/
In this post I describe how to to verify your strongly typed configuration objects are correctly bound to your configuration at app startup
https://andrewlock.net/adding-validation-to-strongly-typed-configuration-objects-in-dotnet-6/
Beta Was this translation helpful? Give feedback.
All reactions