What is the recommended way to convert a rest service to Microservice ?

mehmood tekfirst 771 Reputation points
2022-04-14T08:23:30.32+00:00

Hi,

I want to convert my rest service code to microservice architecture by using Microsoft recommend approach.

This is my code.

This is my service.

   [ApiController]
     [Route("api/[controller]")]
     public class RentalController : ControllerBase
     {
         private readonly IGMManager _gmManager;

         private static readonly string[] Summaries = new[]
         {
         "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
         };

         private readonly ILogger<CarRentalController> _logger;

         public RentalController(ILogger<CarRentalController> logger)
         {
             _logger = logger;
             _gmManager = new GMManager();
         }


         [HttpGet("inquiries")]
         public async Task<ActionResult<List<WebInquiry>>> Inquiries()
         {
            List<WebInquiry> items =  await Task.Run(() =>
             {
                 List<WebInquiry> items = _gmManager.WebInquiry(null);
                 return items;

             });
             return items;
         }      
     }
 }

What are the ways to convert it in Microservice ?

Thank you .

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-04-15T03:33:18.557+00:00

    Hi @mehmood tekfirst ,

    You can refer the following tutorial to create a Microservice with docker, then you can add your service in the API application.

    .NET Tutorial - Your First Microservice

    Microservices Using ASP.NET Core

    Create microservices with .NET and ASP.NET Core


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2022-04-14T17:29:54.74+00:00

    a microservice is an architectural definition, not a framework. they can be a rest api that follows the microservice rules

    • the main rule is that they are deployed independently of other Services. typically CI/CD
    • because they are deployed independently, they should not have breaking changes
    • they should not share application libraries or sdks. that is you can replace the microservice with a new implementation language and framework, without impacting any callers.
    • stateless
    • scaleable via load balancing

    other common rules

    • single database
    • single task (concern)
    • lightweight messages

    basically a micoservice is a url with a well known api. how it is implemented does not matter. typically containers are used for scaling, but you can use AWS lambdas, azure functions, or any scaling web host.

    often a microservice will support swagger or similar so a client can generate a calling wrapper.

    1 person found this answer helpful.
    0 comments No comments

  2. mehmood tekfirst 771 Reputation points
    2022-04-15T06:56:35.417+00:00

    Excellent Bruce and ZhiLv .

    Thank you very much both .

    One thing, what is gRPC in our visual studio template ?


  3. mehmood tekfirst 771 Reputation points
    2022-04-18T06:50:54.863+00:00

    Any good tutorial/walkthrough link for gRPC ?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.