如何根据我放置的数据注解验证此配置?
var dbConfiguration = builder.Configuration.GetSection("AWS:DynamoDB").Get<DynamoDbConfiguration>();
public class DynamoDbConfiguration
{
[Required]
public required string AccessKey { get; init; }
[Required]
public required string SecretKey { get; init; }
[Required]
[RegularExpression(@"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")]
public required string ServiceUrl { get; init; }
[Required]
[RegularExpression(@"(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d+")]
public required string Region { get; init; }
}
1条答案
按热度按时间sqxo8psd1#
输出量:
ValidateDataAnnotations
扩展方法在Microsoft.Extensions.Options.DataAnnotations
NuGet包中定义。对于使用Microsoft.NET.Sdk.Web
SDK的Web应用程序,此包从共享框架中隐式引用。更多详细信息