I have a situation where I'm trying to load configuration via IConfiguration.bind().
public class SettingsCommandInterceptor: ICommandInterceptor
{
public void Intercept(CommandContext context, CommandSettings settings)
{
var confBuilder = new ConfigurationBuilder();
var appConfig = confBuilder.Build();
appConfig.Bind(settings);
}
}
This works great! However, if I depend on this behavior to set properties in my settings when I have a validator, the validator runs before my interceptor raising errors.
public class MyCommandCliOptions : CommandSettings
{
[CommandOption("--username")]
[Description("Username to authenticate")]
public required string AppUsername { get; set; }
[CommandOption("--password")]
[Description("Password to authenticate")]
public required string AppPassword { get; set; }
public override ValidationResult Validate()
{
var baseResult = base.Validate();
if (!baseResult.Successful) return baseResult;
if (AppUsername.IsNullOrEmpty()) return ValidationResult.Error("Username is required.");
if (AppPassword.IsNullOrEmpty()) return ValidationResult.Error("Password is required.");
return ValidationResult.Success();
}
}
In my situation, I have a password that I dont want to be empty, and I want to load from dotnet user secrets instead of passing in an argument every time. Right now I just have to do my validation in my command Execute and throw there, which sucks.
I have a situation where I'm trying to load configuration via
IConfiguration.bind().This works great! However, if I depend on this behavior to set properties in my settings when I have a validator, the validator runs before my interceptor raising errors.
In my situation, I have a password that I dont want to be empty, and I want to load from dotnet user secrets instead of passing in an argument every time. Right now I just have to do my validation in my command Execute and throw there, which sucks.