@@ -19,10 +19,10 @@ public class FluentValidationSubscription : IDisposable
1919 private readonly ValidationMessageStore messages ;
2020
2121 public FluentValidationSubscription (
22- EditContext editContext ,
22+ EditContext editContext ,
2323 IServiceProvider serviceProvider ,
24- bool disableAssemblyScanning ,
25- IValidator validator ,
24+ bool disableAssemblyScanning ,
25+ IValidator validator ,
2626 FluentValidationValidator fluentValidationValidator )
2727 {
2828 this . editContext = editContext ;
@@ -33,11 +33,11 @@ public FluentValidationSubscription(
3333
3434 messages = new ValidationMessageStore ( editContext ) ;
3535
36- editContext . OnValidationRequested += ValidateModel ;
37- editContext . OnFieldChanged += ValidateField ;
36+ editContext . OnFieldChanged += ( _ , _ ) => ValidateModel ( ) ;
37+ editContext . OnValidationRequested += ( _ , _ ) => ValidateModel ( ) ;
3838 }
3939
40- private async void ValidateModel ( object sender , ValidationRequestedEventArgs e )
40+ private async void ValidateModel ( )
4141 {
4242 validator ??= GetValidatorForModel ( serviceProvider , editContext . Model , disableAssemblyScanning ) ;
4343
@@ -75,26 +75,6 @@ private async void ValidateModel(object sender, ValidationRequestedEventArgs e)
7575 }
7676 }
7777
78- private async void ValidateField ( object sender , FieldChangedEventArgs e )
79- {
80- var fieldIdentifier = e . FieldIdentifier ;
81- var properties = new [ ] { fieldIdentifier . FieldName } ;
82- var context = new ValidationContext < object > ( fieldIdentifier . Model , new PropertyChain ( ) ,
83- new MemberNameValidatorSelector ( properties ) ) ;
84-
85- validator ??= GetValidatorForModel ( serviceProvider , fieldIdentifier . Model , disableAssemblyScanning ) ;
86-
87- if ( validator is not null )
88- {
89- var validationResults = await validator . ValidateAsync ( context ) ;
90-
91- messages . Clear ( fieldIdentifier ) ;
92- messages . Add ( fieldIdentifier , validationResults . Errors . Select ( error => error . ErrorMessage ) ) ;
93-
94- editContext . NotifyValidationStateChanged ( ) ;
95- }
96- }
97-
9878 private IValidator GetValidatorForModel ( IServiceProvider serviceProvider , object model ,
9979 bool disableAssemblyScanning )
10080 {
@@ -233,8 +213,8 @@ private FieldIdentifier ToFieldIdentifier(in EditContext editContext, in string
233213
234214 public void Dispose ( )
235215 {
236- editContext . OnFieldChanged -= ValidateField ;
237- editContext . OnValidationRequested -= ValidateModel ;
216+ editContext . OnFieldChanged -= ( _ , _ ) => ValidateModel ( ) ;
217+ editContext . OnValidationRequested -= ( _ , _ ) => ValidateModel ( ) ;
238218 messages . Clear ( ) ;
239219 editContext . NotifyValidationStateChanged ( ) ;
240220 }
0 commit comments