简体   繁体   中英

How to Separate Existing Project using Micro Service Architecture?

I have created one project in asp.net MVC for banking sector.

At the time of development,We did not think about scaling.So we did not used any kind of modular architecture.

But now I am facing lots of problem regarding deployment and development of new feature.

If I develop any new feature then currently I have to release entire project as there is only one namespeace - projectmain.dll.

Now I want to separate all controllers in seperate projects and I want to deploy it seperatly and using MicroService architecture I want to use this in main project.

Note My Views are tightly coupled with controller.

So How can I migrate this entire controllers in MicroService Architecture?

Project Structure Explanation

"How to migrate to microservices" needs a very very long answer that can be a book. I can however, give you some directions that could help you.

First of all, you could follow the DDD approach to help you to correctly identify the bounded context of your application. In an ideal situation, every domain should correspond to a bounded context. So you could split by bounded context. Every bounded context could have one or more microservices, but a microservice should not be larger than a bounded context. From what I see, your controllers are already split by domain or at least by subdomain. You could try to make a microservice for each controller and see how it goes; it is possible to further split, ie by the Aggregate from the DDD (every Aggregate type could be a microservice).

Second, you should have separate projects for each microservice. Ideally, if you want resilience and scalability, a microservice should not call other microservice during an external request. This means that when a microservice receive a request from the clients, it should not call another microservice; for this it should have all the needed data from the other microservices already to its local storage (using background tasks, with synchronous or asynchronous calls).

Last but not least, each microservice should have its own database; they should not share the same database or table.

In this situation, I guess one option would be to convert your controllers into a Web API with each action method returning JSON data instead of returning a view to render. This would now be treated as a separate back end which could be bundled as one micro service. The next step would be to convert your razor views into a purely front end microservice (using a framework like angular or react) with 2 layers-

  1. A service layer responsible for making API calls that fetch the JSON data returned by your Web API
  2. A component layer responsible for mapping the JSON data fetched by your service to your UI elements/forms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM