Hosting multiple web APIs in the same process in .net

30 Views Asked by At

We have a microservice architecture with each microservice currently being hosted in its own process, and deployed via its own docker image. Totally school book separated. On a source level, all services are maintained in the same git repo and in the same solution. We face the same problem as many others, though, with the strict separation. See the paper "Towards Modern Development of Cloud Applications" [1] for elaboration.

How can do a "merge" of our existing services in .net and have them run in the same hosting process? Ultimately, we would like to keep the current service endpoints, for example:

  • example.com/myservice1
  • example.com/myservice2
  • example.com/myservice3

with all services running on the same port, but each serving its own swagger UI? For example:

  • example.com/myservice1/index.html
  • example.com/myservice2/index.html
  • example.com/myservice3/index.html

Context for the above question: .net 6 and web api...

[1] https://pages.cs.wisc.edu/~rgrandl/papers/ms.pdf

2

There are 2 best solutions below

0
John On

I am not sure you can host them in one process. Normally you would use a layer 7 load balancer or proxy to achieve this and route the traffic.

There are many ways to do this either a hosted service like Azure Front Door, nginx in a docker container or software level like YARP Proxy

0
Jalpa Panchal On

You could use docker container or Kestrel behind a reverse proxy or you could use iis server as well to host the NET application that combines multiple microservices into a single process. to achieve your requirement with iis you can consider below steps:

  1. Publish the project from visual studio
  2. configure iis to run the .net application
  3. Create website and under that website you can create multiple application and also create separate app pool to mange each application
  4. To mange the routing you could use iis url rewrite rule IIS also provide proxy facility.