Skip to main content

Posts

Showing posts with the label Asp.net core 3.1

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

A Sample On HttpClientFactory Implementation Using Named Clients Technique In .Net Core Application

An Overview On Named Clients: In HttpClientFactory, the Named Clients technique is useful when an application has a requirement to consume multiple external API's. In the Named Client approach HttpClienFactory produces the HttpClient object specific to the domain. So if our requirement to consume multiple external domains then HttpClientFactory generates HttpClient object per domain based on their registration in a startup.cs file. So each external API domain needs to be registered in the startup.cs file with a specific 'Name' to that HttpClient. This name will be passed to HttpClientFactory to produce a HttpClient object with the specified configuration in the startup.cs file Here we have a configuration object to set time out for the expiration of the HttpClient object. Click here to learn more about an overview of HttpClientFactory Basic Implementation Sample On HttpClientFactory Using HttpRequestMessage Object Test 3rd Party API's: So to understand and implement a s