Posts

Showing posts from December, 2021

Validate Dynamic Model using FluentValidation in ASP.Net Core

Image
  Introduction In an asp.net core validating an input request is a best practice before performing any operation on it. This was generally performed in a middleware using either Microsoft data annotation attributes or using some third-party library like FluentValidation.   We write a validation rule for a static request model and all works fantastic, but what about if your input request model is dynamic? This means the request data is not the same every time. In this article we will see how to validate a model which is dynamic. The Scenario Let us understand the scenario first, we are going to build a generic file transfer API which copies the files to different cloud-based storage. In our example we limit to AWS S3 and Azure Storage. Our API copies the file to the respective cloud based on the settings passed in the request. This is depicted in the below diagram, Figure 1 - File Transfer API Architecture   ...