Creating application with Azure Service Fabric (Part-1)

Varun Malik
3 min readJan 31, 2021

Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. Service Fabric also addresses the significant challenges in developing and managing cloud native applications.

Prerequisite:

Visual Studio 2017/19

Step 1: Download and Install Microsoft Azure Service fabric SDK

Step 2: Open Visual studio Installer and click on Modify to install service fabric tools

With this our local setup for Azure Service Fabric is completed and we can start building our Application.

Step 3: Create new application in Visual Studio and select Service Fabric Application.

Step 4: Select Stateless service and provide a name for your service.

After pressing Create we get two projects created for us. The first project Company, which is a special type of project and describes the whole application in the cluster. It contains a description of how to deploy the application, what are application parameters, and what services it consists of.

Our Reliable service (Employee) is fairly simple. It registers the reliable service, log reliable service has started and then sleeps forever.

Step 5: Add model folder to the Employee project and create EmployeeModel class in it.

Step 6: Add Service folder and create IEmployeeRepositiory interface to it. There are two methods , one for getting employees and another for adding employee.

Step 7: Let’s implement the interface in ServiceFabricEmployeeRepository class. We are using IReliableStateManger to talk to storage and ReliableDictionary (it’s like C# dictionary but reliable) to store employee data.

Step 8: Replace the Employee class default RunAsync method to register our ServiceFabricEmployeeRepository there.

Step 9: Add a new Stateless service to the project by right clicking on Company Project and choose Add -> New Service Fabric Service.

Step 10: We add the model folder to the API project and create Employee class in it. We are doing this so that there is no dependency between the two services.

We will connect the two services and look at the deployment in the Part II.

--

--