Skip to main content

Posts

Showing posts with the label Asp.net core 3.0

Redis Cache Implementation In .NetCore Web API Using Distributed Caching Technique(Redis Docker Instance)

Redis Cache: Redis is an open-source in-memory data structure store, used as a database, cache. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, etc. Setup Redis Docker Instance: For this sample to use Redis instance locally we will use Docker. If you don't have any prior knowledge of docker, not a problem just follow the steps below.  Click here for a video session on Redis docker setup Note: Skip this section if you already have redis direct instance or azure or any cloud provider that have redis Step1: Download docker into our local system "https://docs.docker.com/desktop/" . Docker was available for all desktop operating systems. Step2: After downloading the docker installer, then install it. Now to run any docker containers(eg: Redis, MongoDB, PostgreSQL, etc) this docker instance we just installed should be active(should be running). Step3: Now we need to pull the docker Redis image from the docker hub "http

Localization In .NetCore MVC Application

Localization: The translation to a specific region or country or culture or local. The websites with localization can reach a wider range of audiences. Create A DotNet Core MVC Sample Application: Let's learn localization steps by implementing them in a sample MVC application. Add Sample Language Collection To AppSettings File: In our sample let's read the different languages that we support from the appSettings.json file. appSettings.Development.json: "LanguageCodes": [ { "Name": "Spain", "Code": "es" }, { "Name": "Mexico", "Code": "es-Mx" }, { "Name": "United States", "Code": "en-us" } ] Let's create a type for the "LanguageCodes". Shared/LanguageCodes: namespace Sample.Localization.Mvc.Shared { public class LanguageCodes { public string Name { get; set; } public string Code { get; set; } } } Register

A Sample On .Net Core Web API Using Dapper

Overview On Dapper Object-Relational Mapping: Dapper is an Object-Relational Mapping framework for .Net applications. It is a mapping model between the database and .Net objects. The Dapper provides all query and command execution methods as extension methods under the 'System.Data.IDbConnection' interface. The Dapper works as a similar ADO.Net but with much more model mapping support. The Dapper key features are like: High performance in query execution Multiple query execution support An easy model mapping between the .Net Object and database result. Create A Sample .Net Core Web API Application: Let's understand the Dapper ORM query and commands execution steps by writing some sample code, so let's get started by creating a .Net Core Web API application. The IDE's for development can be chosen by personal preference but the most recommended IDE's are Visual Studio 2019 and  Visual Studio Code . SQL Table Schema: In this article we are going to work on 'T

A Sample On HttpClientFactory Using Typed Client Technique In .Net Core Application

In .Net Core, using HttpClientFacotory is the recommended way to consume the Rest API. The HttpClientFactory can be implemented using the following techniques. Using HttpRequestMessage Object Named Client Typed Client Typed Client: Typed Client technique is to implement or create a separate entity or class file per API domain. So all Http communication implementations are registered in a specific class per API domain. In this approach, each entity or class will be injected with 'System.Net.Http.HttpClient' object by the 'HttpClienFacotry'. So in this approach, we will not use 'HttpClientFactory' directly like we did for 'Named Client' and 'Using HttpRequestMessage Object' techniques. In simple words for consuming one third-party rest API need to create a specific class for it, if we have 'n' number of rest APIs to consume in our project then we need to create 'n' number of classes to implement the HttpClientFactory logic specific

.Net Core Sample Example On HttpClientFactory Basic Implementation With HttpRequestMessage Object.

In this article, we are going to see the HTTP client factory's basic implementation technique to consume an API in our .Net Core application.  Click here to understand how HttpClientFactory works. Create A Sample API Project: Now let's create a .net core web API sample project in which we are going to consume another API(Third-party API) using HttpClientFactory. You can create your sample project using editors like Visual Studio 2019 or  Visual Studio Code . Test API To Consume: Let's consume a free Rest API to consume for our leaning process. There a lot of free developer API for learning purposes. Here we are going to use JSONPlaceholder. JSONPlaceholder: Guide :- https://jsonplaceholder.typicode.com/guide.html Endpoints:- 1.https://jsonplaceholder.typicode.com/users/1/todos (Todos endpoint) 2.https://jsonplaceholder.typicode.com/users/1/albums (Albums endpoint) 3.https://jsonplaceholder.typicode.com/albums/1/photos (Photos endpoint) 4.https://jsonplaceholder.typicode.