A comprehensive .NET project template for creating Azure Functions microservices with a complete project structure including documentation, testing, and domain modeling.
This template provides a scaffolded solution for Azure Function microservices following best practices for enterprise development. It creates a well-structured solution with separation of concerns, comprehensive testing setup, and documentation generation.
- Azure Functions Service: Ready-to-use Azure Function app with dependency injection setup
- Domain Layer: Shared domain models and business logic
- Comprehensive Testing: Both unit and integration test projects
- Documentation: Automated documentation generation setup
- Template Parameters: Customizable company, application, and component names
- EditorConfig: Consistent code formatting across the team
- Solution Structure: Well-organized folder structure following .NET best practices
- .NET 6.0 SDK or later
- Azure Functions Core Tools (for local development)
- Visual Studio 2022 or Visual Studio Code with C# extension
-
Clone this repository:
git clone https://github.com/AdiThakker/Azure.Function.Template.git cd Azure.Function.Template -
Pack the template:
dotnet pack
-
Install the template locally:
dotnet new install ./nupkg/AdiThakker.Azure.Function.Template.1.0.0.nupkg
dotnet new install AdiThakker.Azure.Function.TemplateUse the template to create a new Azure Function microservice:
dotnet new adifunctionappservice -n MyNewService -o ./MyNewService --company "MyCompany" --application "MyApp" --component "MyComponent"| Parameter | Required | Default Value | Description |
|---|---|---|---|
company |
Yes | "Your Company name" | The company name that will replace "Company" in all files and namespaces |
application |
Yes | "Your Application name" | The application name that will replace "Application" in all files and namespaces |
component |
Yes | "Your Component name" | The component name that will replace "Component" in all files and namespaces |
includeIntegrationTest |
No | true |
Whether to include integration test project in the generated solution |
# Create a new service for Contoso's inventory management
dotnet new adifunctionappservice \
--name InventoryService \
--output ./ContosInventoryService \
--company "Contoso" \
--application "Retail" \
--component "Inventory"This will create a solution with the following namespaces:
Contoso.Retail.Inventory.ServiceContoso.Retail.Inventory.DomainContoso.Retail.Inventory.UnitTestContoso.Retail.Inventory.IntegrationTest
After using the template, you'll get the following structure:
YourProject/
├── Documentation/
│ └── Company.Application.Component.Documentation/
│ ├── Company.Application.Component.Documentation.csproj
│ └── [Documentation generation setup]
├── Source/
│ ├── Company.Application.Component.Service/
│ │ ├── Company.Application.Component.Service.csproj
│ │ ├── Startup.cs
│ │ ├── host.json
│ │ └── Properties/
│ └── Shared/
│ └── Company.Application.Component.Domain/
│ └── Company.Application.Component.Domain.csproj
├── Testing/
│ ├── Company.Application.Component.UnitTest/
│ │ └── Company.Application.Component.UnitTest.csproj
│ └── Company.Application.Component.IntegrationTest/
│ ├── Company.Application.Component.IntegrationTest.csproj
│ └── Program.cs
├── .editorconfig
└── Company.Application.Component.sln
- Service Project: The main Azure Functions application with dependency injection configured
- Domain Project: Shared domain models, entities, and business logic
- Unit Test Project: Unit tests for your business logic and functions
- Integration Test Project: End-to-end tests for your Azure Functions
- Documentation Project: Setup for generating API documentation
-
Build the solution:
dotnet build
-
Run tests:
dotnet test -
Run Azure Functions locally:
cd Source/[YourCompany].[YourApplication].[YourComponent].Service func start -
Add new functions:
- Add new function classes to the Service project
- Register dependencies in
Startup.cs - Add corresponding tests
The template includes a basic host.json configuration file. Customize it according to your needs:
{
"version": "2.0",
"functionTimeout": "00:05:00",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true
}
}
}
}Dependencies are configured in the Startup.cs file:
public override void Configure(IFunctionsHostBuilder builder)
{
// Register your services here
builder.Services.AddScoped<IYourService, YourService>();
}- Separation of Concerns: Keep business logic in the Domain project
- Dependency Injection: Use the built-in DI container for managing dependencies
- Testing: Write comprehensive unit and integration tests
- Configuration: Use Azure App Configuration or Key Vault for sensitive settings
- Monitoring: Implement Application Insights for monitoring and logging
- Security: Follow Azure Functions security best practices
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-new-feature - Make your changes and add tests
- Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/my-new-feature - Submit a pull request
To modify the template:
- Edit files in the
templates/Azure.FunctionServiceTemplate.Scaffolding/directory - Update
template.jsonfor new parameters or configuration - Test the template by packing and installing locally
- Submit a pull request with your changes
- Template not found: Make sure you've installed the template correctly
- Build errors: Ensure all required parameters are provided
- Missing dependencies: Run
dotnet restorein the generated solution
- Check the Azure Functions documentation
- Review the .NET CLI documentation
- Open an issue in this repository for template-specific problems
This project is licensed under the MIT License - see the LICENSE file for details.
Adi Thakker
- Email: [Contact information]
- GitHub: @AdiThakker
- Microsoft Azure Functions team for the excellent platform
- .NET team for the powerful templating engine
- Contributors who help improve this template
- 1.0.0: Initial release with basic Azure Function microservice template
- Azure Functions service project
- Domain modeling support
- Unit and integration testing setup
- Documentation generation
- Customizable naming parameters