Project Setup for Microservices in ASP.NET Core Web API

Project Setup for Microservices in ASP.NET Core Web API

In this article, I will explain the Project Setup for Microservices in ASP.NET Core Web API. Please read our previous article discussing the Architecture of Microservices.

Project Setup for Microservices in ASP.NET Core Web API

In this article, we will look at the microservices for the Vehicle Test Drive application. Let’s assume that there is some famous automobile company like Tesla and people like me want a test drive of some particular vehicle. So, we’ll create microservices for vehicle test drive Applications.

Project Setup for Microservices in ASP.NET Core Web API

The application is relatively small, but this will give you a perfect jumpstart in the world of microservices. The basic flow of this application will create three microservices.

  • Used to handle the vehicle’s data.
  • Used to handle the customer’s data.
  • Used to handle the reservation data.

Now, let’s assume, there is a mobile application that wants to consume these microservices. It will display the vehicle list data. The data will come from the vehicle microservice.

Project Setup for Microservices in ASP.NET Core Web API

After selecting a particular vehicle, we’ll get further details of the vehicle.

Project Setup for Microservices in ASP.NET Core Web API

Now, when we click on the Book Test Drive option, we have been asked to provide the following details i.e. the customer details who wants a test drive of that particular vehicle.

Project Setup for Microservices in ASP.NET Core Web API

Once we provide these details, then this data goes to the customer’s microservice and similarly, this data will also go to the Azure messaging service.

Project Setup for Microservices in ASP.NET Core Web API

Now, there is also an end in the application where the admin can add, update, and delete the vehicle’s data and the admin can also send emails to those customers who are interested in the test drive of the selected vehicles.

Project Setup for Microservices in ASP.NET Core Web API

So, when the admin opens the application and clicks the reservation option. He will see the list of customers who are interested in test drive of some particular vehicle and this data will come from Azure Service Bus.

Project Setup for Microservices in ASP.NET Core Web API

Then the admin can send the email to these customers for confirmation.

Project Setup for Microservices in ASP.NET Core Web API

Creating Solution for Microservices

We’re going to create an empty project solution and three microservices projects. It’s better if you create a different solution for your projects for microservices, but this will also consume more RAM and processing power. So, instead of opening different instances of Visual Studio, we’ll just open one instance of Visual Studio. This will create one solution that contains all the microservices projects.

Step 1: Open the Visual Studio 2022 and create a new project.

So, open Visual Studio 2022 and click on the Create a new project option as shown in the below image to create a new project.

Open the Visual Studio 2022 and create a new project

Once you click on the Create a new project option, it will open the following Create a new project window. In this window, search for the blank solution and then select the Blank Solution, and click on the Next button. The Blank Solution Project Template will create an empty solution containing no projects.

Blank Solution Project Template

Once you click on the Next button, it will open the following Configure your new project window. Here, we need to provide a meaningful name for our solution and select the location where you want to create this project. I am providing the solution name as VehicleTestDrive and then click on the Create button as shown in the below image.

Configure your new project window

Once you click on the Create button, the solution will be created without any projects as shown in the below image.

Configure your new project window

Now inside this solution, we’re going to add three different Web API projects i.e. VehiclesAPI, CustomersAPI, and ReservationsAPI

Step 2: Creating VehiclesAPI Project

Right-click on the solution and then select Add => New Project from the context menu which will open the following Add New Project window. From this window, select the ASP.NET Core Web API Project template and then click on the Next button as shown in the below image.

Creating VehicleAPI Project

Once you click on the Next button, it will open the following configure your new project window. In this window, provide the project name as VehiclesAPI, go with the default project location, and finally click on the Next button as shown in the below image.

Project Setup for Microservices in ASP.NET Core Web API

Once you click on the Next button, it will open the following Additional Information window. Here, I am using the .NET 6.0 framework. We don’t need authentication and docker that’s why we don’t need to change anything here. Then make sure to Enable API support because this will add the swagger API documentation for us. You can also check the Use Controllers and Do Not Use Top Level Statements check box and then click on the Create button as shown in the below image.

Creating VehicleAPI Project

Once you click on the Create and Our Vehicle Web API project has been created and should be added to the solution.

Step 3: Creating CustomersAPI and ReservationsAPI

Now we will create other 2 ASP.NET Core Web API Projects i.e. CustomersAPI and ReservationsAPI. You need to follow the same steps that we follow to add the VehicleAPI Project. With all these three projects i.e. VehicleAPI, CustomersAPI, and ReservationsAPI, our solution should look as follows:

Microservices in ASP.NET Core Web API

Install NuGet Packages

Now we will add the NuGet Packages inside these Microservices Projects.

  • Package for Entity Framework Core: Microsoft.EntityFrameworkCore
  • Package for SQL Server Database: Microsoft.EntityFrameworkCore.SqlServer
  • The last one for Migration Purposes: Microsoft.EntityFrameworkCore.Tools
Installing Package for Entity Framework Core

To add these packages to all the projects, right-click on the solution and then select Manage NuGet Packages for Solution which will open the following Manage Packages for Solution window. Now, select the Browse tab, and inside the search bar, search for Entity Framework Core Package and then select all three projects before starting the installation as shown in the below image.

Installing Package for Entity Framework Core

Once you click on the Install button, one popup will come up for Review Changes, Simply click on the Ok button, and then another popup will open to access the License, simply click on the I Accept button.

Installing Entity Framework Core Tools

Now search for Entity Framework Core Tools package and also select all three projects before starting the installation as shown in the below image.

Installing Entity Framework Core Tools

Installing SQL Server Database Package:

Now search for the SQL Server database package and select all three projects before starting the installation as shown in the image below.

Installing SQL Server Database Package

So, we have installed all the necessary packages. As we progress in this course, will also install other packages when required.

In the next article, I am going to discuss How to Create Microservices for Vehicles. In this article, I try to explain the Project Setup for Microservices using ASP.NET Core Web API. I hope you enjoy this Project Setup for Microservices using the ASP.NET Core Web API article.

Leave a Reply

Your email address will not be published. Required fields are marked *