Skip to content

Instantly share code, notes, and snippets.

@Boggin
Created December 19, 2025 09:53
Show Gist options
  • Select an option

  • Save Boggin/e173d2fe6782d3d8d870d5bd23327267 to your computer and use it in GitHub Desktop.

Select an option

Save Boggin/e173d2fe6782d3d8d870d5bd23327267 to your computer and use it in GitHub Desktop.
Demo for minimum Aspire project

Demo for minimum Aspire project

Introduction

How to create a minimum Aspire project that uses Service Bus and Event Hub emulators with a Function App.

This was tested with .net10

Setup

Assuming the dotnet CLI is already installed.

  mkdir test; cd test
  dotnet new install Aspire.ProjectTemplates
  dotnet new aspire-starter
  dotnet new gitignore
  dotnet sln migrate; rm *.sln
  dotnet dev-certs https --trust
  dotnet run --project .\test.AppHost\test.AppHost.csproj

Add Integrations

Assuming the Aspire CLI is already installed.

  aspire update --self
  aspire update
  aspire add azure-servicebus
  aspire add azure-eventhubs

Update AppHost

Update the AppHost.cs to add Event Hubs and Service Bus emulators.

var eventHubs =
    builder.AddAzureEventHubs("event-hubs")
        .RunAsEmulator();
eventHubs.AddHub("messages");

// The name given to the AddAzureServiceBus() method must match the 
// name expected by the function's trigger's 'Connection' parameter.
var serviceBus =
    builder.AddAzureServiceBus("service-bus")
        .RunAsEmulator();
serviceBus.AddServiceBusQueue("servicebus-queue");

Add Function App

winget install Microsoft.Azure.FunctionsCoreTools
aspire add azure-functions
mkdir test.Function; cd .\test.Function\
func init --worker-runtime dotnet-isolated --target-framework net10.0
func new --template "ServiceBusQueueTrigger" --name "TestServiceBusQueueTrigger"
cd ..
dotnet reference add .\test.ServiceDefaults\test.ServiceDefaults.csproj --project .\test.Function\test_Function.csproj
dotnet reference add .\test.Function\test_Function.csproj --project .\test.AppHost\test.AppHost.csproj
dotnet sln add .\test.Function\test_Function.csproj

Update Function App

The connection and the queue names set in the AppHost must be used in the trigger.

[ServiceBusTrigger("servicebus-queue", Connection = "service-bus")]

The function's Program should call the ServiceDefaults.

builder.AddServiceDefaults();

Add Function App to AppHost

In AppHost.cs.

builder.AddAzureFunctionsProject<Projects.test_Function>("functions")
    .WithReference(serviceBus)
    .WaitFor(serviceBus)
    .WithReference(eventHubs)
    .WaitFor(eventHubs);

Run the application

dotnet run --project .\test.AppHost\test.AppHost.csproj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment