# CSharp Microservices

Organizing a C# project for microservices architecture using Azure Container Apps involves careful planning, structuring, and setting up. Here is one of the best ways to do this:

1. Services Division: Start by dividing your application into different services. Each service should have a single responsibility and should be loosely coupled, i.e., independent and self-contained.
2. Project Folder Structure: Create separate folders for each microservice in your project. Within each microservice, you can further divide into smaller parts. Here is an example of a typical folder structure:

```
├─── .github                 # contains GitHub workflows and actions
├─── Microservice1
|      ├─── Controllers      # contains API controllers
|      ├─── Services         # business logic goes here
|      ├─── Middleware       # Middlewares if any
|      ├─── Models           # contains domain models
|      ├─── Properties       # application properties
|      └─── Utils            # utility functions/classes
|
├─── Microservice2
|
└─── docker-compose.yml
```

3. Dockerization: Dockerize each microservice, create a Dockerfile within each service directory. This file should contain instructions to create a Docker image for the respective microservice.
4. Docker Compose: Having Dockerfiles for each service, consider bringing them together using a docker-compose.yml. It should contain the services and the instructions to run them.
5. Azure Container Apps: Azure Container Apps is a serverless container hosting service. Deploy your Docker container to Azure Container Apps as it handles orchestration, routing, scaling, and SSL offloading for you. You can set up pipelines in Azure DevOps to provide continuous integration and deployment.
6. Separation of Concerns: For projects following microservices architecture, it's preferable to set up separate repositories for each service. This ensures that the services are decoupled from each other.
7. Unit Tests: Create a tests project for each microservice to ensure that all functions are working as expected. This helps in maintaining the quality of code. Resources:

* For a detailed walkthrough on creating microservices with Azure Kubernetes Service, you can refer to <https://docs.microsoft.com/en-us/learn/modules/aks-workshop/>. Though it uses Kubernetes, many of the concepts and steps are the same.
* Check out Microsoft's E-Shop containers on <https://github.com/dotnet-architecture/eShopOnContainers>, this is a full .NET core application built with microservices architecture, Dockerized and deployed on various cloud platforms including Azure.
* For Azure Container Apps, a detailed how-to guide can be found on <https://docs.microsoft.com/en-us/azure/container-apps/microservices-overview>. Please note the "best way" can change based on requirements, team size, existing tech stack, and several other factors. The given approach is a commonly used one, but the architecture can differ based on the specific needs of the project.
* learn.microsoft.comlearn.microsoft.com Introduction to Kubernetes on Azure - Training Learn about the basics of Docker containers, container orchestration with Kubernetes, and managed clusters on Azure Kubernetes Service.

GitHubGitHub GitHub - dotnet-architecture/eShopOnContainers: Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor. Moved to <https://github.com/dotnet/eShop>. Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual St... (98 kB)

* <https://github.com/dotnet-architecture/eShopOnContainers>
