Sep 24, 2020 05:33 PM|PJM8765|LINK
Thanks, clearly I don't understand the Blazor lifecycle. Early days yet.
So, all the services I am ever going to use in the component have to be substantiated during that initial request i.e. during the OnInitialised(Async) event handler, or earlier, yes? But, critically, a model class and it's validator attributes are inaccessible
because they cannot have dependencies coming from the direction of consuming code....or can they? I'm going to assume they can't for now.
So the answer is that for Blazor it cannot be done as a nicely encapsulated model based custom ValidationAttribute. That's a mark back for MVC for me (currently the score is 1-1).
So, I'm going to tag a nice old fashioned method on to my Organisation class (organisation.GetValidationMessages()) which at least maintains a degree of encapsulation, whilst I write yet more code that I shouldn't really have to and use the ValidationMessageStore.
Its not exactly difficult to misunderstand the documents MS have written for Blazor. They vary from being ropey to downright rubbish (as with the link you attached). But thankfully someone else has
done their job for them it appears.