Add a GetService method to ModelValidatorProviderContext class #62044
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Uh oh!
There was an error while loading. Please reload this page.
Add new methos to and existing class
In ASP.NET Core when I'm going to build my own validation provider, I have to register it to work with the built-in on that is provided by ASP.NET Core framework, I have to implement two interfaces:
The IModelValidatorProvider has a method named CreateValidators and accept on parameter of type ModelValidatorProviderContext object.
In this method you may need to resolve some dependency object and to do that you have to inject the IServiceCollection interface and us it like so:
Instead of doing that my suggestion here is to add a new method to this class (ModelValidatorProviderContext) named GetService and should accept one parameter of type Type object
Here is the new method:
And now here I can user the GetService method without needing to inject IServiceCollection interface to the object constructor:
Usage Examples
Here is my complete custom validator provider object:
The text was updated successfully, but these errors were encountered: