This project demonstrates how to develop an Azure Function application that can be used to manage a catalog of products. There are multiple versions of the same project where each new version increases in functionality and complexity.
The goal of this project is to introduce Azure Function concepts by slowly introducing them in different project versions. The following Azure Function concepts will be demonstrated:
- Azure triggers (http, blob, servicebus)
- Azure bindings (blob)
- In-process and Isolated Process
- Dependency Injection
- Local development
- Infrastructure as Code (Bicep, Azure CLI, Azure Powershell)
The available versions are as follows:
-
Create inital Product Manager Function App having the following functionality:
- Add 'ProductsFunction' function (HTTP Triggered) to serve as products API.
-
Extend Product Manager Version 1 with the following changes:
- Add depedency injection
- Use in-memory database provided by Entity Framework
- Modify 'ProductsFunction' function to use dependency injection and in-memory database
- Add 'SeedFunction' function to help seed the products database
-
Extend Product Manager Version 2 with the following changes:
- Modify the 'ProductsFunction' function to include product images
- Add Azure Storage integration to store product images
- Add 'user secrets' to store connection information
-
Extend Product Manager Version 3 with the following changes:
- Add 'ProductImageResizerFunction' function that uses a 'Blob Trigger' to react to newly uploaded product images by resizing product images to 3 sizes (xs, sm, md) and uploading them to an Azure Storage Container.
- The 'ProductImageResizerFunction' function also saves new product image data to a relevant product in the database.
- Update 'ProductsFunction' function to accomodate additional product image information.
-
Extend Product Manager Version 4 with the following changes:
- Use Cosmos Db as primary database
- Add CosmosDbService as a convenient wrapper of CosmosClient
- Create ProductService to handle all product management
- Create ProductImageService to handle all product image requirements
- Introduce hashing to produce product entity id
- Create ProductFaker (uses Bogus library) to seed Cosmos Db database
Before you get started, make sure you have the following requirements in place:
- .NET 6.0 SDK
- Azure Functions Core Tools version 4.x
- Visual Studio Code on one of the supported platforms
- C# extension for Visual Studio Code
- Azure Functions extension for Visual Studio Code
- Azure Storage Emulator. See my guide on getting started with Azure Storage.
You also need an Azure account with an active subscription. Create an account for free
All Azure Function examples require access to Azure Storage. For development, the [Azurite] emulator is recommended by Microsoft for local Azure Storage development.
According to the official Microsoft documentation:
The Azurite open-source emulator provides a free local environment for testing your Azure blob, queue storage, and table storage applications.
Find more information about Azurite by visiting the following links:
- Use the Azurite emulator for local Azure Storage development
- Official Azure Azurite Github Repository
I recommend using Azurite via the NPM approach as follows:
# Install Azurite
npm install -g azurite
# Run Azurite
azurite --silent --location ~/azurite --debug ~/azurite/debug.log
# Get Help
azurite -h
azurite --help
Azure Storage Explorer allows one to upload, download, and manage Azure Storage blobs, files, queues, and tables, as well as Azure Data Lake Storage entities and Azure managed disks.
Download the official tool offering from microsoft called Azure Storage Explorer
Alternatively, if you have not done so already, install the Azure Tools extension pack for Visual Studio Code.
# open product manager workspace folder
cd azure-dotnet-examples/functions/product-manager
# open product manager workspace
code ./product-manager.code-workspace