I made a custom PasswordValidator with its own set of options:
class MyValidator : Identity.PasswordValidator<TUser>
{
Task<IdentityResult> ValidateAsync(UserManager<TUser> manager, TUser user, string password)
{
var options = // retrieve options
if (options.CustomRule.Matches(password))
// etc
}
}
class MyPasswordOptions : Identity.PasswordOptions
{
object CustomRule { get; set; }
}
Now I want to access an instance of MyPasswordOptions in MyValidator. I can, for example:
- simply register this class in Startup.cs like any options class, and inject it in the constructor of MyValidator;
- pass an instance of the MyPasswordOptions class to the options.Password property in services.AddIdentity(), and inject IdentityOptions in the constructor of MyValidator.
Microsoft's original implementation however accesses the options through an internal property of UserManager, which seems like the best option to me, if it wasn't internal.
Question: What is Microsoft's intended way to access the options in Asp Identity Core in a custom implementation? Say, I did not have a custom options class. I still could not easily access the IdentityOptions in the MyValidator class, without injecting them. While the original class (Identity.PasswordValidator) could.