From this article, you will gain a knowledge on how to access appsettings.json properties or configuration values inside Custom Validation Attribute class.

To achieve this, First We should have a custom validation attribute class that implements ValidationAttribute class.

Add Override IsValid method inside our custom validator class.

Please find the sample code snippet for this scenario,

We are going to write a unit test for the line no’s 10 and 12 using MOQ framework.

The following code has IConfiguration and IServiceProvider interfaces because these two are dependencies to our CustomValidator class. All these are mocking using MOQ framework.

It’s your turn now to use the above code snippet and pass your own values and test it. I believe this article helps you to solve your problem and saves your valuable time.

— Happy Learning

--

--

Article saves you a lot of time in your day-to-day work especially creating a model using JSON data.

In visual studio IDE there is a feature called “Paste JSON as Class” which is coming under the Edit Menu and inside of Paste Special sub-menu.

In general, Once we have any data in any format we use it to create a class with properties and variables manually.

With “ Paste JSON as Class” feature in visual studio saves you a lot of conversion time.

In order to achieve that we need JSON data. The above snapshot shows you how we can convert JSON data to Class using Visual Studio IDE.

— Happy Coding :)

Originally published at https://techinuthan.blogspot.com.

--

--

Nuthan Murarysetty

Nuthan Murarysetty

5 Followers

I love sharing things what I know to others and passionate in photography.