up
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using StellaOps.DependencyInjection.Validation;
|
||||
|
||||
namespace StellaOps.Plugin.MyConnector;
|
||||
|
||||
/// <summary>
|
||||
/// Validates <see cref="MyConnectorOptions"/> configuration.
|
||||
/// </summary>
|
||||
public sealed class MyConnectorOptionsValidator : OptionsValidatorBase<MyConnectorOptions>
|
||||
{
|
||||
protected override string SectionPrefix => MyConnectorOptions.SectionName;
|
||||
|
||||
protected override void ValidateOptions(MyConnectorOptions options, ValidationContext context)
|
||||
{
|
||||
context
|
||||
.RequireNotEmpty(options.BaseUrl, nameof(options.BaseUrl))
|
||||
.RequirePositive(options.TimeoutSeconds, nameof(options.TimeoutSeconds))
|
||||
.RequireInRange(options.MaxRetries, nameof(options.MaxRetries), 0, 10);
|
||||
|
||||
// Validate URL format
|
||||
if (!string.IsNullOrWhiteSpace(options.BaseUrl) &&
|
||||
!Uri.TryCreate(options.BaseUrl, UriKind.Absolute, out _))
|
||||
{
|
||||
context.AddError(nameof(options.BaseUrl), "must be a valid absolute URL.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user