-
-
Save tugberkugurlu/3852195 to your computer and use it in GitHub Desktop.
A custom DataAnnotationsModelValidatorProvider that injects IServiceProvider into ValidationContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomDataAnnotationsModelValidatorProvider : DataAnnotationsModelValidatorProvider | |
{ | |
private readonly IServiceProvider serviceProvider; | |
public CustomDataAnnotationsModelValidatorProvider(IServiceProvider serviceProvider) | |
{ | |
this.serviceProvider = serviceProvider; | |
DataAnnotationsModelValidatorProvider.RegisterDefaultAdapterFactory( | |
(metadata, context, attribute) => | |
new CustomDataAnnotationsModelValidator(serviceProvider, metadata, context, attribute) | |
); | |
DataAnnotationsModelValidatorProvider.RegisterDefaultValidatableObjectAdapterFactory( | |
(metadata, context) => new CustomValidatableObjectAdapter(serviceProvider, metadata, context) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have example code of this working? I seem to be having a hard time getting this implemented in my DDD project.