This is a simple Blazor web application to illustrate common basic usage of Azure Cosmos DB for MongoDB's client library for .NET. This sample application accesses an existing account, database, and container using the Microsoft.Azure.Cosmos
and Azure.Identity
libraries from NuGet. Modify the source code and leverage the Infrastructure as Code (IaC) Bicep assets to get up and running quickly.
When you are finished, you will have a fully functional web application deployed to Azure.
Screenshot of the deployed web application.
This template will create infrastructure and deploy code to Azure. If you don't have an Azure Subscription, you can sign up for a free account here. Make sure you have the contributor role in the Azure subscription.
The following prerequisites are required to use this application. Please ensure that you have them all installed locally.
To learn how to get started with any template, follow the steps in this quickstart with this template (cosmos-db-mongodb-dotnet-quickstart
).
This quickstart will show you how to authenticate on Azure, initialize using a template, provision infrastructure and deploy code on Azure via the following commands:
# Log in to azd. Only required once per-install.
azd auth login
# First-time project setup. Initialize a project in the current directory, using this template.
# Omit the --template argument if you are running in a development container.
azd init --template cosmos-db-mongodb-dotnet-quickstart
# Provision and deploy to Azure
azd up
This application utilizes the following Azure resources:
- Azure Container Registry
- This services hosts the container image.
- Azure Container Apps
- This service hosts the ASP.NET Blazor web application.
- Azure Cosmos DB for MongoDB
- This service stores the collection data.
Here's a high level architecture diagram that illustrates these components. Notice that these are all contained within a single resource group, that will be created for you when you create the resources.
%%{ init: { 'theme': 'base', 'themeVariables': { 'background': '#243A5E', 'primaryColor': '#50E6FF', 'primaryBorderColor': '#243A5E', 'tertiaryBorderColor': '#50E6FF', 'tertiaryColor': '#243A5E', 'fontFamily': 'Segoe UI', 'lineColor': '#FFFFFF', 'primaryTextColor': '#243A5E', 'tertiaryTextColor': '#FFFFFF' } }}%%
flowchart TB
subgraph web-app[Azure Container Apps]
app-framework([.NET 8 - Blazor])
end
subgraph cosmos-db[Azure Cosmos for MongoDB]
subgraph database-cosmicworks[Database: cosmicworks]
subgraph container-products[Container: products]
prd-yamba[Product: Yamba Surfboard]
prd-kiama-classic[Product: Kiama Classic Surfboard]
end
end
end
web-app --> cosmos-db
This template provisions resources to an Azure subscription that you will select upon provisioning them. Refer to the Pricing calculator for Microsoft Azure to estimate the cost you might incur when this template is running on Azure and, if needed, update the included Azure resource definitions found in infra/main.bicep
to suit your needs.
This template is structured to follow the Azure Developer CLI. You can learn more about azd
architecture in the official documentation.
At this point, you have a complete application deployed on Azure. But there is much more that the Azure Developer CLI can do. These next steps will introduce you to additional commands that will make creating applications on Azure much easier. Using the Azure Developer CLI, you can setup your pipelines, monitor your application, test and debug locally.
-
azd pipeline config
- to configure a CI/CD pipeline (using GitHub Actions or Azure DevOps) to deploy your application whenever code is pushed to the main branch. -
Run and Debug Locally - using Visual Studio Code and the Azure Developer CLI extension
-
azd down
- to delete all the Azure resources created with this template