Skip to main content

Posts

Model Validation In Asp.Net Core Application Using Fluent Validation Library

In this article, we will explore the usage of the Fluent Validation library in the Asp.Net Core application. Fluent Validation Library: Fluent Validation is a popular .Net library for enabling validation rules. It has a lot of features like in-built validation rules that are most commonly used in any application and also has flexible support for creating custom rules. Implementing Fluent validation rules is a cleaner approach than using the 'DataAnnotation'(.Net default implementation for applying validation rules). It can be automatically injected into .NetCore model validations without any explicit implementation. How To Implement Fluent Validation To A Model: To apply fluent validation to the model, we have to create a separate validator class. The validator class must inherit from 'FluentValidation.AbstractValidator<TModel>'. Inside of the constructor need to apply required validation for the properties of 'TModel'. public class Student { public

AutoMapper In Asp.Net Core Applications

AutoMapper: Automapper is an object-to-object mapper. Object to object mapping works by transforming an input object of one type into an output object of a different type. Manually mapping one object property value to another object property value leads to more lines of code, so all this dirty work can be avoided by using the Automapper. As long as all properties names are the same for 2 different objects that need to map, almost zero configuration is needed to map them.  When To Use AutoMapper?: In any kind of architecture, it is always advised to not expose the 'Entity'(Table classes) directly. So we will create replica classes for 'Entity' we called them as 'DTO'(Data Transfer Object) or 'VM'(View Models). So this is the real-time best case to use Automapper for mapping 'Entity'(Table classes) data to DTO or VM's. Create A Sample Dotnet5 Web API Project: In this demo, we are going to understand the different mapping techniques that are

An Overview On SameSite Cookie Options In Dotnet Core Application

The SameSite cookie option is used by the browsers to determine whether to attach or remove the cookie for a request. So to understand all the options of SameSite cookie, here we are going to check different scenarios with the help of 2 different domains like "http://mycookieapp.com/" and 'http://mythirdparty.com/' . The  "http://mycookieapp.com/" is a dotnet5 MVC application where have login cookie authentication enabled, so here we will check the SameSite option for my login cookie(SameSite option applied to any kind of cookie, here I'm just using the login cookie for my testing). So here I enable the 'Authorization' attribute on my index page, so only authenticated users can access it. The  'http://mythirdparty.com/' is a normal dotnet5 MVC application where we consume the  "http://mycookieapp.com/" website as a link or iframe. AspNet Core Cookie SameSite Options: The following are the cookie SameSite options: Strict Lax Non

Vue 3 Consume GraphQL Endpoint Using Vue Apollo

In this article, we are going to implement Vue 3 sample application that consumes GrpahQL Endpoint using the Vue Apollo library. Create Vue 3 Application: Let's create a sample Vue 3 application to accomplish our demo. Vue CLI Command To Create Project: vue create your_project_name GraphQL Server Endpoint: We should have a GraphQL server endpoint for our demo. So I created a GraphQL server endpoint using 'Dotnet', so I'm going to use it here so its URL be like 'https://localhost:6001/graphql'. So please make sure to have your own GraphQL server endpoint. Install Vue Apollo And Its Dependent Libraries: npm install --save @vue/apollo-option npm install --save @apollo/client npm install --save graphql npm install --save graphql-tag One more plugin we have to install 'react', at the time of this article written we will get an error that says that need to install the 'react', so this 'react' installation might be avoided in feature r

A Demo On Angular(v12) Pagination Using Angular Material UI Paginator Component

In this article, we are going to implement pagination using angular material in a sample angular(version 12) application. Create A Sample Angular Application: Let's create a sample angular project and also install the angular material package. Install Angular CLI: npm install -g @angular/cli Command To Create Angular Application: ng new your-project-name Command To Install Angular Material Package: ng add @angular/material API: Here I'm going to use a sample pagination API that I had created. Here I will show the sample response to gain the basic idea over the API. Create Response Models: Now let's create models to read the API JSON response. ng g class models/todo.model ng g class models/todo.paging.model models/todo.model.ts: export interface TodoModel { id:number; itemName: string; isCompleted:boolean; } models/todo.paging.model.ts: import { TodoModel } from "./todo.model"; export interface TodoPagingModel { data: TodoModel[], totalC

A Demo On MudBlazor Table Pagination In Blazor WebAssembly

In this article, we are going to implement pagination in the Blazor WebAssembly application using the MudBlazor UI table component. Pagination API: To accomplish our demo we need an API endpoint that contains a payload to support the pagination. If you have good knowledge of API pagination you can create your own API or else I have already created a blog on API pagination, so  click here  to know more. Create A Blazor WebAssembly Project: Let's begin our coding by creating a sample Blazor WebAssembly project. Steps To Configure MudBlazor: Let's install the 'MudBlazor' NuGet into our sample project. Now add the MudBlazor namespace into the '_Import.razor' file. _Import.razor: @using MudBlazor Add the below CSS files inside of the head tag of the 'index.html'. wwwroot/index.html: <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" /> <link href="_content