{"id":2042,"date":"2023-07-17T12:09:26","date_gmt":"2023-07-17T12:09:26","guid":{"rendered":"http:\/\/waqar-arshad.com\/?p=2042"},"modified":"2023-07-17T12:09:26","modified_gmt":"2023-07-17T12:09:26","slug":"microservices","status":"publish","type":"post","link":"http:\/\/waqar-arshad.com\/index.php\/2023\/07\/17\/microservices\/","title":{"rendered":"Microservices"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"2042\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"2042\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>\n<p>Microservices<\/p>\n\n\n\n<p>The term microservices portrays a software development style that has grown from contemporary trends to set up practices that are meant to increase the speed and efficiency of developing and managing software solutions at scale. Microservices is more about applying a certain number of principles and architectural patterns as architecture. Each microservice lives independently, but on the other hand, also all rely on each other. All microservices in a project get deployed in production at their own pace, on-premise on the cloud, independently, living side by side.<\/p>\n\n\n\n<p>In this article, we will learn the concept of Microservices, their architecture, and how to create microservices in .NET and C#. You will also learn steps to&nbsp;build, deploy, and test microservices in .NET using a docker container.<\/p>\n\n\n\n<p>Microservices Architecture<\/p>\n\n\n\n<p>The following picture from Microsoft Docs shows the microservices architecture style.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"515\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-66.png\" alt=\"\" class=\"wp-image-2043\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-66.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-66-300x164.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-66-768x421.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>There are various components in a microservices architecture apart from microservices themselves.<\/p>\n\n\n\n<p><strong>Management<\/strong>. Maintains the nodes for the service.<\/p>\n\n\n\n<p><strong>Identity Provider<\/strong>. Manages the identity information and provides authentication services within a distributed network.<\/p>\n\n\n\n<p><strong>Service Discovery<\/strong>. Keeps track of services and service addresses and endpoints.<\/p>\n\n\n\n<p><strong>API Gateway<\/strong>. Serves as client\u2019s entry point. Single point of contact from the client which in turn returns responses from underlying microservices and sometimes an aggregated response from multiple underlying microservices.<\/p>\n\n\n\n<p><strong>CDN<\/strong>. A content delivery network to serve static resources for e.g. pages and web content in a distributed network<\/p>\n\n\n\n<p><strong>Static Content<\/strong>&nbsp;The static resources like pages and web content<\/p>\n\n\n\n<p>Microservices are deployed independently with their own database per service so the underlying microservices look as shown in the following picture.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"339\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-67.png\" alt=\"\" class=\"wp-image-2044\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-67.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-67-300x108.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-67-768x277.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Monolithic vs Microservices Architecture<\/p>\n\n\n\n<p>Monolithic applications are more of a single complete package having all the related needed components and services encapsulated in one package.<\/p>\n\n\n\n<p>Following is the diagrammatic representation of monolithic architecture being package completely or being service based.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"543\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-68.png\" alt=\"\" class=\"wp-image-2045\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-68.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-68-300x173.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-68-768x444.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Microservice is an approach to create small services each running in their own space and can communicate via messaging. These are independent services directly calling their own database.<\/p>\n\n\n\n<p>Following is the diagrammatic representation of microservices architecture.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"516\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-69.png\" alt=\"\" class=\"wp-image-2046\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-69.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-69-300x165.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-69-768x422.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>In monolithic architecture, the database remains the same for all the functionalities even if an approach of service-oriented architecture is followed, whereas in microservices each service will have its own database.<\/p>\n\n\n\n<p>Docker Containers and Docker installation<\/p>\n\n\n\n<p>Containers like Dockers and others slice the operating system resources, for e.g. the network stack, processes namespace, file system hierarchy and the storage stack. Dockers are more like virtualizing the operating system. Learn more about dockers&nbsp;<a href=\"https:\/\/www.docker.com\/resources\/what-container\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Open&nbsp;<a href=\"https:\/\/docs.docker.com\/docker-for-windows\/install\/\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a>&nbsp;URL and click on Download from Docker hub. Once downloaded, login to the Docker and follow instructions to install Docker for Windows.<\/p>\n\n\n\n<p>Microservice using ASP.NET Core<\/p>\n\n\n\n<p>This section will demonstrate how to create a Product microservice using ASP.NET Core step by step with the help of pictures. The service would be built using ASP.NET Core 2.1 and Visual Studio 2017. Asp.NET Core comes integrated with VS 2017. This service will have its own DBcontext and database with the isolated repository so that the service could be deployed independently.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"354\" height=\"298\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-70.png\" alt=\"\" class=\"wp-image-2047\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-70.png 354w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-70-300x253.png 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<p>Creating an ASP.NET Core Application Solution<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"587\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-72.png\" alt=\"\" class=\"wp-image-2049\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-72.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-72-300x187.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-72-768x480.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Choose the application as ASP.NET Core Web Application and give it a meaningful name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"534\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-73.png\" alt=\"\" class=\"wp-image-2050\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-73.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-73-300x170.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-73-768x436.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Next, choose API as the type of the project and make sure that \u201cEnable Docker Support\u201d option is selected with OS type as Linux.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"664\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-74.png\" alt=\"\" class=\"wp-image-2051\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-74.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-74-300x212.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-74-768x543.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>The solution will look as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"559\" height=\"593\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-75.png\" alt=\"\" class=\"wp-image-2052\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-75.png 559w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-75-283x300.png 283w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><\/figure>\n\n\n\n\n\n<p>Adding Models<\/p>\n\n\n\n<p>Add a new folder named \u201cModel\u201d to the project<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"611\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-76.png\" alt=\"\" class=\"wp-image-2053\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-76.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-76-300x195.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-76-768x499.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>In the Models folder, add a class named Product.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"482\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-77.png\" alt=\"\" class=\"wp-image-2054\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-77.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-77-300x154.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-77-768x394.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Add a few properties like Id, Name, Description, Price to the product class. The product should also be of some kind and for that, a category model is defined and a CategoryId property is added to the product model.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"351\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-78.png\" alt=\"\" class=\"wp-image-2055\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-78.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-78-300x112.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-78-768x287.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Similarly, add Category model.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"328\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-79.png\" alt=\"\" class=\"wp-image-2056\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-79.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-79-300x105.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-79-768x268.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li><\/li>\n<\/ol>\n\n\n\n<p><strong>Enabling EF Core<\/strong><\/p>\n\n\n\n<p>Though .NET Core API project has inbuilt support for EF Core and all the related dependencies are downloaded at the time of project creation and compilation that could be found under SDK section in the project as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"606\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-80.png\" alt=\"\" class=\"wp-image-2057\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-80.png 840w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-80-300x216.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-80-768x554.png 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p>Microsoft.EntityFrameworkCore.SqlServer (2.1.1) should be the package inside the downloaded SDK\u2019s. If it is not present, it could be explicitly added to the project via Nuget Packages.<\/p>\n\n\n\n<p>Adding EF Core DbContext<\/p>\n\n\n\n<p>Add a new folder named DBContexts to the project.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"716\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-81.png\" alt=\"\" class=\"wp-image-2058\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-81.png 689w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-81-289x300.png 289w\" sizes=\"auto, (max-width: 689px) 100vw, 689px\" \/><\/figure>\n\n\n\n<p>Add a new class named ProductContext which includes the DbSet properties for Products and Categories. OnModelCreating is a method via which the master data could be seeded to the database. So, add the OnModelCreating method and add some sample categories that will be added to the database initially into the category table when the database is created.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"556\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-82.png\" alt=\"\" class=\"wp-image-2059\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-82.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-82-300x177.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-82-768x454.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p><strong>ProductContext code<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li><\/li>\n\n\n\n<li>\u00a0<\/li>\n\n\n\n<li>using Microsoft.EntityFrameworkCore;<\/li>\n\n\n\n<li>using ProductMicroservice.Models;<\/li>\n\n\n\n<li>namespace ProductMicroservice.DBContexts<\/li>\n\n\n\n<li>{<\/li>\n\n\n\n<li>&nbsp;&nbsp;public class ProductContext : DbContext<\/li>\n\n\n\n<li>&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public ProductContext(DbContextOptions&lt;ProductContext&gt; options) : base(options)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public DbSet&lt;Product&gt; Products { get; set; }<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public DbSet&lt;Category&gt; Categories { get; set; }<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;protected override void OnModelCreating(ModelBuilder modelBuilder)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modelBuilder.Entity&lt;Category&gt;().HasData(<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Category<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id = 1,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = &#8220;Electronics&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description = &#8220;Electronic Items&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Category<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id = 2,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = &#8220;Clothes&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description = &#8220;Dresses&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Category<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id = 3,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = &#8220;Grocery&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Description = &#8220;Grocery Items&#8221;,<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;}<\/li>\n\n\n\n<li>}<\/li>\n<\/ol>\n\n\n\n<p>C#<\/p>\n\n\n\n<p>Copy<\/p>\n\n\n\n<p>Add a connection string in the appsettings.json file.<br><br><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"201\" src=\"\" alt=\"Microservice Using ASP.NET Core\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"313\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-83.png\" alt=\"\" class=\"wp-image-2060\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-83.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-83-300x100.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-83-768x256.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Open the Startup.cs file to add the SQL server db provider for EF Core. Add the code services.AddDbContext&lt;ProductContext&gt;(o =&gt; o.UseSqlServer(Configuration.GetConnectionString(&#8220;ProductDB&#8221;))); under ConfigureServices method. Note that in the GetConnectionString method the name of the key of the connection string is passed that was added in appsettings file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"356\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-84.png\" alt=\"\" class=\"wp-image-2061\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-84.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-84-300x114.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-84-768x291.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Adding Repository<\/p>\n\n\n\n<p>Repository works as a micro component of microservice that encapsulates the data access layer and helps in data persistence and testability as well.<\/p>\n\n\n\n<p>Add a new folder named Repository in the project and add an Interface name IProductRepository in that folder. Add the methods in the interface that performs CRUD operations for Product microservice.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"377\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-85.png\" alt=\"\" class=\"wp-image-2062\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-85.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-85-300x120.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-85-768x308.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Add a new concrete class named ProductRepository in the same Repository folder that implements IProductRepository. All these methods need:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"391\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-86.png\" alt=\"\" class=\"wp-image-2063\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-86.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-86-300x125.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-86-768x319.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li><\/li>\n\n\n\n<li>Add the implementation for the methods via accessing context methods.<br><br><strong>ProductRepository.cs<\/strong><\/li>\n\n\n\n<li>using Microsoft.EntityFrameworkCore;<\/li>\n\n\n\n<li>using ProductMicroservice.DBContexts;<\/li>\n\n\n\n<li>using ProductMicroservice.Models;<\/li>\n\n\n\n<li>using System;<\/li>\n\n\n\n<li>using System.Collections.Generic;<\/li>\n\n\n\n<li>using System.Linq;<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>namespace ProductMicroservice.Repository<\/li>\n\n\n\n<li>{<\/li>\n\n\n\n<li>&nbsp;&nbsp;public class ProductRepository: IProductRepository<\/li>\n\n\n\n<li>&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;private readonly ProductContext _dbContext;<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public ProductRepository(ProductContext dbContext)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_dbContext = dbContext;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public void DeleteProduct(int productId)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var product = _dbContext.Products.Find(productId);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_dbContext.Products.Remove(product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public Product GetProductByID(int productId)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return _dbContext.Products.Find(productId);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IEnumerable&lt;Product&gt; GetProducts()<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return _dbContext.Products.ToList();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public void InsertProduct(Product product)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_dbContext.Add(product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save();&nbsp;&nbsp;&nbsp; }<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public void Save()<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_dbContext.SaveChanges();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public void UpdateProduct(Product product)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_dbContext.Entry(product).State = EntityState.Modified;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Save();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;}<\/li>\n<\/ol>\n\n\n\n<p>}<\/p>\n\n\n\n<p>C#<\/p>\n\n\n\n<p>Open the Startup class in the project and add the code as services.AddTransient&lt;IProductRepository, ProductRepository>(); inside ConfigureServices method so that the repository\u2019s dependency is resolved at a run time when needed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"461\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-87.png\" alt=\"\" class=\"wp-image-2064\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-87.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-87-300x147.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-87-768x377.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p><strong>Adding Controller<\/strong><\/p>\n\n\n\n<p>The microservice should have an endpoint for which a controller is needed which exposes the HTTP methods to the client as endpoints of the service methods.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"684\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-88.png\" alt=\"\" class=\"wp-image-2065\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-88.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-88-300x218.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-88-768x559.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Right click on the Controllers folder and add a new Controller as shown below.<\/p>\n\n\n\n<p>Select the option \u201cAPI Controller with read\/write actions\u201d to add the controller.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"650\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-89.png\" alt=\"\" class=\"wp-image-2066\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-89.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-89-300x207.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-89-768x531.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Give the name of the controller as ProductController.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"189\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-90.png\" alt=\"\" class=\"wp-image-2067\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-90.png 916w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-90-300x62.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-90-768x158.png 768w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/figure>\n\n\n\n<p>A ProductController class will be added in the Controllers folder with default read\/write actions that will be replaced later with product read\/write actions and HTTP methods are created acting as an endpoint of the service.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"405\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-91.png\" alt=\"\" class=\"wp-image-2068\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-91.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-91-300x129.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-91-768x331.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>ValuesController can be deleted as it is not needed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"262\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-92.png\" alt=\"\" class=\"wp-image-2069\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-92.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-92-300x84.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-92-768x214.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Add implementation to the methods by calling the repository methods as shown below. The basic implementation is shown here for the sake of understanding the concept. The methods could be attribute routed and could be decorated with more annotations as per need.<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li><br><strong>ProductController.c<\/strong>s<\/li>\n\n\n\n<li>using Microsoft.AspNetCore.Mvc;<\/li>\n\n\n\n<li>using ProductMicroservice.Models;<\/li>\n\n\n\n<li>using ProductMicroservice.Repository;<\/li>\n\n\n\n<li>using System;<\/li>\n\n\n\n<li>using System.Collections.Generic;<\/li>\n\n\n\n<li>using System.Transactions;<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>namespace ProductMicroservice.Controllers<\/li>\n\n\n\n<li>{<\/li>\n\n\n\n<li>&nbsp;&nbsp;[Route(&#8220;api\/[controller]&#8221;)]<\/li>\n\n\n\n<li>&nbsp;&nbsp;[ApiController]<\/li>\n\n\n\n<li>&nbsp;&nbsp;public class ProductController : ControllerBase<\/li>\n\n\n\n<li>&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;private readonly IProductRepository _productRepository;<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public ProductController(IProductRepository productRepository)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_productRepository = productRepository;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;[HttpGet]<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IActionResult Get()<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var products = _productRepository.GetProducts();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new OkObjectResult(products);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;[HttpGet(&#8220;{id}&#8221;, Name = &#8220;Get&#8221;)]<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IActionResult Get(int id)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var product = _productRepository.GetProductByID(id);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new OkObjectResult(product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;[HttpPost]<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IActionResult Post([FromBody] Product product)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using (var scope = new TransactionScope())<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_productRepository.InsertProduct(product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope.Complete();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return CreatedAtAction(nameof(Get), new { id = product.Id }, product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;[HttpPut]<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IActionResult Put([FromBody] Product product)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (product != null)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using (var scope = new TransactionScope())<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_productRepository.UpdateProduct(product);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope.Complete();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new OkResult();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new NoContentResult();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;[HttpDelete(&#8220;{id}&#8221;)]<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;public IActionResult Delete(int id)<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_productRepository.DeleteProduct(id);<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new OkResult();<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}<\/li>\n\n\n\n<li>&nbsp;&nbsp;}<\/li>\n<\/ol>\n\n\n\n<p>}<\/p>\n\n\n\n<p>C#<\/p>\n\n\n\n<p>Copy<\/p>\n\n\n\n<p>Entity Framework Core Migrations<\/p>\n\n\n\n<p>Migrations allow us to provide code to change the database from one version to another.<\/p>\n\n\n\n<p>Open Package Manager Console.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"630\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-93.png\" alt=\"\" class=\"wp-image-2070\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-93.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-93-300x201.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-93-768x515.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>To enable the migration, type the command, Add-Migration and give that a meaningful name for e.g. InitialCreate and press enter.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"189\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-95.png\" alt=\"\" class=\"wp-image-2072\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-95.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-95-300x60.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-95-768x154.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Once the command is executed, if we look at our solution now, we see there&#8217;s a new Migrations folder. And it contains two files. One, a snapshot of our current context model. Feel free to check the files. The files are very much self-explanatory.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"591\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-96.png\" alt=\"\" class=\"wp-image-2073\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-96.png 596w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-96-300x297.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-96-150x150.png 150w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p>To ensure that migrations are applied to the database there&#8217;s another command for that. It&#8217;s called the update-database If executed, the migrations will be applied to the current database.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"307\" height=\"34\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-97.png\" alt=\"\" class=\"wp-image-2074\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-97.png 307w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-97-300x33.png 300w\" sizes=\"auto, (max-width: 307px) 100vw, 307px\" \/><\/figure>\n\n\n\n<p>Check the SQL Server Management Studio to verify if the database got created.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"285\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-98.png\" alt=\"\" class=\"wp-image-2075\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-98.png 404w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-98-300x212.png 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/figure>\n\n\n\n<p>When data of the Categories table is viewed the default master data of three categories is shown.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"522\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-99.png\" alt=\"\" class=\"wp-image-2076\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-99.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-99-300x167.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-99-768x426.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>ValuesController can be deleted as it is not needed.<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li><\/li>\n<\/ol>\n\n\n\n<p>Run the Product Microservice<\/p>\n\n\n\n<p>The service could be run via IIS Express i.e. Visual Studio default or via Docker container as well.<\/p>\n\n\n\n<p>Via IIS Express<\/p>\n\n\n\n<p>Choose IIS Express in the Visual Studio as shown below and press F5 or click that IIS Express button itself.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"123\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-100.png\" alt=\"\" class=\"wp-image-2077\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-100.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-100-300x39.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-100-768x100.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>The application will be up once the browser page is launched. Since it has nothing to show, it will be blank, but the service could be tested via any API testing client. Here Postman is used to testing the service endpoints. Keep it opened and application running.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"226\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-101.png\" alt=\"\" class=\"wp-image-2078\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-101.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-101-300x72.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-101-768x185.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Install Postman if it is not on the machine and launch it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"615\" height=\"964\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-102.png\" alt=\"\" class=\"wp-image-2079\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-102.png 615w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-102-191x300.png 191w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><\/figure>\n\n\n\n<p><strong>POST<\/strong><\/p>\n\n\n\n<p>To test the POST method; i.e. create a new resource, select the method as POST in postman and provide the endpoint, i.e.&nbsp;https:\/\/localhost:44312\/api\/product&nbsp;and in the Body section, add a JSON similar to having properties of Product model as shown below and click on Send.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"224\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-103.png\" alt=\"\" class=\"wp-image-2080\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-103.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-103-300x71.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-103-768x183.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>The response is returned with the Id of the product as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"594\" height=\"251\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-104.png\" alt=\"\" class=\"wp-image-2081\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-104.png 594w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-104-300x127.png 300w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/figure>\n\n\n\n<p>The \u201cPost\u201d method of the controller is responsible to create a resource in the database and send the response.<\/p>\n\n\n\n<p>The line return CreatedAtAction(nameof(Get), new { id=product.Id }, product); returns the location of the created resource that could be checked in Location attribute in the response under Headers tab.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"328\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-105.png\" alt=\"\" class=\"wp-image-2082\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-105.png 907w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-105-300x108.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-105-768x278.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<p>Perform a select query on the product table and an added row is shown for the newly created product.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"564\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-106.png\" alt=\"\" class=\"wp-image-2083\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-106.png 769w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-106-300x220.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/figure>\n\n\n\n<p>Create one more product in a similar way.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"772\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-107.png\" alt=\"\" class=\"wp-image-2084\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-107.png 724w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-107-281x300.png 281w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/figure>\n\n\n\n<p><strong>GET<\/strong><\/p>\n\n\n\n<p>Perform a GET request now with the same address and two records are shown as a JSON result response.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"411\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-108.png\" alt=\"\" class=\"wp-image-2085\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-108.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-108-300x131.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-108-768x336.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p><strong>DELETE<\/strong><\/p>\n\n\n\n<p>Perform the delete request by selecting DELETE as the verb and appending id as 1 (if the product with id 1 needs to be deleted) and press Send.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"103\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-109.png\" alt=\"\" class=\"wp-image-2086\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-109.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-109-300x33.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-109-768x84.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>In the database, one record with Id 1 gets deleted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"727\" height=\"298\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-110.png\" alt=\"\" class=\"wp-image-2087\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-110.png 727w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-110-300x123.png 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/figure>\n\n\n\n<p><strong>PUT<\/strong><\/p>\n\n\n\n<p>PUT verb is responsible for updating the resource. Select PUT verb, provide the API address and in the Body section, provide details of which product needs to be updated in JSON format. For example, update the product with Id 2 and update its name, description, and price from Samsung to iPhone specific. Press Send.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"261\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-111.png\" alt=\"\" class=\"wp-image-2088\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-111.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-111-300x83.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-111-768x213.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Check the database to see the updated product.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"330\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-112.png\" alt=\"\" class=\"wp-image-2089\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-112.png 682w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-112-300x145.png 300w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/figure>\n\n\n\n<p><strong>Via Docker Containers<\/strong><\/p>\n\n\n\n<p>Running the service could be done via docker commands to be run in docker command prompt and using visual studio as well. Since we added the docker support, it is easy to run the service in docker container using visual studio.<\/p>\n\n\n\n<p>Add container orchestrator support in the solution as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"451\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-113.png\" alt=\"\" class=\"wp-image-2090\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-113.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-113-300x144.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-113-768x368.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>This will ask for the orchestrator. Select Docker Compose and press OK.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"181\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-114.png\" alt=\"\" class=\"wp-image-2091\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-114.png 573w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-114-300x95.png 300w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/figure>\n\n\n\n<p>Once added to the solution, the solution will look like shown below having docker-compose with dockerignore and docker-compose.yml and its override file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"572\" height=\"181\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-115.png\" alt=\"\" class=\"wp-image-2092\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-115.png 572w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-115-300x95.png 300w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li>As soon as the solution is saved, it builds the project under the container and creates a docker image. All the commands execution can be seen in the output window when the solution is saved.<\/li>\n<\/ol>\n\n\n\n<p>Open the command prompt in admin mode and navigate to the same folder where the project files are.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"966\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-116.png\" alt=\"\" class=\"wp-image-2093\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-116.png 608w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-116-189x300.png 189w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/figure>\n\n\n\n<p>Run the command docker images to see all the created images. We see the ProductMicroserviceimage the latest one.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"226\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-117.png\" alt=\"\" class=\"wp-image-2094\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-117.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-117-300x72.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-117-768x185.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Now run the application with Docker as an option as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"249\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-118.png\" alt=\"\" class=\"wp-image-2095\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-118.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-118-300x79.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-118-768x203.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Now, run the command docker ps to see the running containers. It shows the container is running on 32773:80 port.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"57\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-119.png\" alt=\"\" class=\"wp-image-2096\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-119.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-119-300x18.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-119-768x47.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Since the container is in running state, it is good to test the service now running under the container. To test the service, replace \u201dvalues\u201d with \u201cproduct\u201d in the address as shown below. Ideally, it should get the product details. But it gives exception as shown below.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"348\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-120.png\" alt=\"\" class=\"wp-image-2097\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-120.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-120-300x111.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-120-768x284.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Running the same thing under IIS Express works fine i.e. on port 44312. Replace \u201cvalues\u201d with the product to get the product details,<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"211\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-121.png\" alt=\"\" class=\"wp-image-2098\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-121.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-121-300x67.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-121-768x172.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li>Since in IIS Express application runs fine and not in docker container, the error clearly shows that something is wrong with the SQL server that it does not understand our docker container or it is not running under docker container. In this scenario, the docker container is running as a separate machine inside the host computer. So, to connect to the SQL database in the host machine, remote connections to SQL needs to be enabled. We can fix this.<br>&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Open the SQL Server Configuration Manager. Now select Protocols for MSSQLSERVER and get the IPAll port number under TCP\/IP section.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"476\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-122.png\" alt=\"\" class=\"wp-image-2099\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-122.png 880w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-122-300x162.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-122-768x415.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"394\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-123.png\" alt=\"\" class=\"wp-image-2100\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-123.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-123-300x126.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-123-768x322.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"634\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-124.png\" alt=\"\" class=\"wp-image-2101\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-124.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-124-300x202.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-124-768x518.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"533\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-125.png\" alt=\"\" class=\"wp-image-2102\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-125.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-125-300x170.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-125-768x435.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>The connection string mentioned in the JSON file points to the data source as local which the docker container does not understand. It needs proper IP addresses with port and SQL authentication. So, provide the relevant details i.e. Data Source as Ip address, port number and SQL authentication details as shown below.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"260\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-126.png\" alt=\"\" class=\"wp-image-2103\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-126.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-126-300x83.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-126-768x212.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Now again run the application with Docker as an option like done earlier.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"211\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-127.png\" alt=\"\" class=\"wp-image-2104\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-127.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-127-300x67.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-127-768x172.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li>This time the response is received.<\/li>\n<\/ol>\n\n\n\n<p>Test the same in the Postman.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"374\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-128.png\" alt=\"\" class=\"wp-image-2105\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-128.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-128-300x119.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-128-768x306.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Test again with IIS Express URL.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"533\" src=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-129.png\" alt=\"\" class=\"wp-image-2106\" srcset=\"http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-129.png 940w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-129-300x170.png 300w, http:\/\/waqar-arshad.com\/wp-content\/uploads\/2023\/07\/image-129-768x435.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>A microservice is a service built around a specific business capability, which can be independently deployed which is called bounded context. This article on microservices focused on what microservices are and their advantages over monolithic services architecture. The article in detail described to develop a microservice using ASP.NET Core and run it via IIS and Docker container. Likewise, the service can have multiple images and could be run on multiple containers at the same point in time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microservices The term microservices portrays a software development style that has grown from contemporary trends to set up practices that are meant to increase the speed and efficiency of developing and managing software solutions at scale. Microservices is more about applying a certain number of principles and architectural patterns as architecture. Each microservice lives independently, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2042","post","type-post","status-publish","format-standard","hentry","category-microservices"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"http:\/\/waqar-arshad.com\/index.php\/author\/waqar_29_1\/"},"uagb_comment_info":37,"uagb_excerpt":"Microservices The term microservices portrays a software development style that has grown from contemporary trends to set up practices that are meant to increase the speed and efficiency of developing and managing software solutions at scale. Microservices is more about applying a certain number of principles and architectural patterns as architecture. Each microservice lives independently,&hellip;","_links":{"self":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/2042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/comments?post=2042"}],"version-history":[{"count":1,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/2042\/revisions"}],"predecessor-version":[{"id":2107,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/2042\/revisions\/2107"}],"wp:attachment":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/media?parent=2042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/categories?post=2042"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/tags?post=2042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}