Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
751a694
Enhance Dapr support in Aspire framework
FullStackChef Aug 7, 2025
990118a
Enhance Dapr support in Aspire framework
FullStackChef Aug 7, 2025
cf76351
Merge branch 'task-refactor' of https://github.com/FullStackChef/Comm…
FullStackChef Aug 22, 2025
aabfc9e
Integrate Azure Dapr support into CommunityToolkit
FullStackChef Aug 23, 2025
e9ccba2
Enhance Azure Container App Dapr integration
FullStackChef Aug 25, 2025
e56d9c6
Enhance Dapr support in Aspire framework
FullStackChef Aug 7, 2025
f22021b
Enhance Dapr support in Aspire framework
FullStackChef Aug 7, 2025
31750eb
Integrate Azure Dapr support into CommunityToolkit
FullStackChef Aug 23, 2025
1e0b657
Enhance Azure Container App Dapr integration
FullStackChef Aug 25, 2025
484b42f
Remove IDistributedApplicationBuilderExtensions class
FullStackChef Sep 18, 2025
971c15b
Refactor Dapr integration for Azure Redis Cache
FullStackChef Sep 18, 2025
dc627a4
Delete examples/dapr/CommunityToolkit.Aspire.Hosting.Azure.Dapr.AppHo…
FullStackChef Sep 18, 2025
369f533
Delete examples/dapr/CommunityToolkit.Aspire.Hosting.Azure.Dapr.AppHo…
FullStackChef Sep 18, 2025
9d8379b
Delete examples/dapr/CommunityToolkit.Aspire.Hosting.Azure.Dapr.AppHo…
FullStackChef Sep 18, 2025
95ca8d1
Add tests for Dapr component references and sidecar functionality
FullStackChef Sep 20, 2025
297f184
remove sln file
FullStackChef Sep 20, 2025
e52472d
Merge remote-tracking branch 'origin/main' into task-refactor
FullStackChef Sep 20, 2025
1afa00b
Enhance Dapr sidecar configuration with default AppId and options han…
FullStackChef Sep 21, 2025
5dc3410
Refactor Dapr sidecar configuration to simplify AppId handling and re…
FullStackChef Sep 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureContainerAppEnvironment("cae").WithDaprComponents();

var redis = builder.AddAzureRedis("redisState").WithAccessKeyAuthentication().RunAsContainer();
var redis = builder.AddAzureRedis("redisState")
.RunAsContainer();

// local development still uses dapr redis state container
// State store using Redis
var stateStore = builder.AddDaprStateStore("statestore")
.WithReference(redis);
.WithReference(redis)
.WithMetadata("actorStateStore", "true");

// PubSub also using Redis - for Azure deployment this will use the same Redis instance
var pubSub = builder.AddDaprPubSub("pubsub")
.WithMetadata("redisHost", "localhost:6379")
.WithReference(redis)
.WaitFor(redis);


builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceA>("servicea")
.WithReference(stateStore)
.WithReference(pubSub)
.WithDaprSidecar()
.PublishAsAzureContainerApp((i,c)=> { })
.WithDaprSidecar(sidecar => sidecar.WithReference(stateStore).WithReference(pubSub))
.WaitFor(redis);

builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceB>("serviceb")
.WithReference(pubSub)
.WithDaprSidecar()
.WithDaprSidecar(sidecar => sidecar.WithReference(pubSub))
.WaitFor(redis);

// console app with no appPort (sender only)
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceC>("servicec")
.WithReference(stateStore)
.WithDaprSidecar()
.WithDaprSidecar(sidecar => sidecar.WithReference(stateStore))
.WaitFor(redis);

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
.WaitFor(redis);

builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceA>("servicea")
.WithReference(stateStore)
.WithReference(pubSub)
.WithDaprSidecar()
.WaitFor(pubSub);
.WithDaprSidecar(sidecar =>
{
sidecar.WithReference(stateStore).WithReference(pubSub);
}).WaitFor(redis);

builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceB>("serviceb")
.WithReference(pubSub)
.WithDaprSidecar()
.WaitFor(pubSub);
.WithDaprSidecar(sidecar => sidecar.WithReference(pubSub))
.WaitFor(redis);

// console app with no appPort (sender only)
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceC>("servicec")
.WithReference(stateStore)
.WithDaprSidecar()
.WaitFor(stateStore);
.WithDaprSidecar(sidecar => sidecar.WithReference(stateStore))
.WaitFor(redis);

builder.Build().Run();

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
using Aspire.Hosting.Azure.AppContainers;
using Azure.Provisioning.AppContainers;
using CommunityToolkit.Aspire.Hosting.Azure.Dapr;
using CommunityToolkit.Aspire.Hosting.Dapr;

namespace Aspire.Hosting;

/// <summary>
/// Provides extension methods for configuring Azure Container App Environment resources.
/// </summary>
public static class AzureContainerAppEnvironmentResourceBuilderExtensions
{
/// <summary>
/// Configures the Azure Container App Environment resource to use Dapr.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithDaprComponents(
this IResourceBuilder<AzureContainerAppEnvironmentResource> builder)
{
builder.ApplicationBuilder.AddDapr(c =>
{
c.PublishingConfigurationAction = (IResource resource, DaprSidecarOptions? daprSidecarOptions) =>
{
var configureAction = (AzureResourceInfrastructure infrastructure, ContainerApp containerApp) =>
{
containerApp.Configuration.Dapr = new ContainerAppDaprConfiguration
{
AppId = daprSidecarOptions?.AppId ?? resource.Name,
AppPort = daprSidecarOptions?.AppPort ?? 8080,
IsApiLoggingEnabled = daprSidecarOptions?.EnableApiLogging ?? false,
LogLevel = daprSidecarOptions?.LogLevel?.ToLower() switch
{
"debug" => ContainerAppDaprLogLevel.Debug,
"warn" => ContainerAppDaprLogLevel.Warn,
"error" => ContainerAppDaprLogLevel.Error,
_ => ContainerAppDaprLogLevel.Info
},
AppProtocol = daprSidecarOptions?.AppProtocol?.ToLower() switch
{
"grpc" => ContainerAppProtocol.Grpc,
_ => ContainerAppProtocol.Http,
},
IsEnabled = true
};
};

resource.Annotations.Add(new AzureContainerAppCustomizationAnnotation(configureAction));
};
});

return builder.ConfigureInfrastructure(infrastructure =>
{
var daprComponentResources = builder.ApplicationBuilder.Resources.OfType<IDaprComponentResource>();

foreach (var daprComponentResource in daprComponentResources)
{
daprComponentResource.TryGetLastAnnotation<AzureDaprComponentPublishingAnnotation>(out var publishingAnnotation);

publishingAnnotation?.PublishingAction(infrastructure);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;

namespace CommunityToolkit.Aspire.Hosting.Azure.Dapr;
/// <summary>
/// Represents an annotation that defines a publishing action for Azure Dapr components.
/// </summary>
/// <remarks>This annotation is used to specify a custom action that is executed during the publishing process of
/// Azure Dapr components. The action is applied to the provided <see cref="AzureResourceInfrastructure"/> instance,
/// allowing customization of the resource infrastructure.</remarks>
/// <param name="PublishingAction">The action to be executed on the <see cref="AzureResourceInfrastructure"/> during the publishing process. This
/// action allows for customization of the infrastructure configuration.</param>
public record AzureDaprComponentPublishingAnnotation(Action<AzureResourceInfrastructure> PublishingAction) : IResourceAnnotation;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Azure.Provisioning.AppContainers;
using Azure.Provisioning.Expressions;
using Azure.Provisioning;
using Azure.Provisioning.KeyVault;
using CommunityToolkit.Aspire.Hosting.Dapr;

namespace Aspire.Hosting;
Expand All @@ -14,30 +13,6 @@ namespace Aspire.Hosting;
public static class AzureDaprHostingExtensions
{


/// <summary>
/// Adds an Azure Dapr resource to the resource builder.
/// </summary>
/// <param name="builder">The resource builder.</param>
/// <param name="name">The name of the Dapr resource.</param>
/// <param name="configureInfrastructure">The action to configure the Azure resource infrastructure.</param>
/// <returns>The updated resource builder.</returns>
public static IResourceBuilder<AzureDaprComponentResource> AddAzureDaprResource(
this IResourceBuilder<AzureDaprComponentResource> builder,
[ResourceName] string name,
Action<AzureResourceInfrastructure> configureInfrastructure)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));
ArgumentException.ThrowIfNullOrEmpty(name, nameof(name));
ArgumentNullException.ThrowIfNull(configureInfrastructure, nameof(configureInfrastructure));

var azureDaprComponentResource = new AzureDaprComponentResource(name, configureInfrastructure);

return builder.ApplicationBuilder
.AddResource(azureDaprComponentResource)
.WithManifestPublishingCallback(azureDaprComponentResource.WriteToManifest);
}

/// <summary>
/// Adds an Azure Dapr resource to the resource builder.
/// </summary>
Expand All @@ -63,49 +38,6 @@ public static IResourceBuilder<AzureDaprComponentResource> AddAzureDaprResource(
.WithManifestPublishingCallback(azureDaprComponentResource.WriteToManifest);
}

/// <summary>
/// Configures the infrastructure for a Dapr component in a container app managed environment.
/// </summary>
/// <param name="builder"></param>
/// <param name="daprComponent">The Dapr component to configure.</param>
/// <param name="parameters">The parameters to provide to the component</param>
/// <param name="requireScopes">Whether scopes need to be assigned to the component</param>
/// <returns>An action to configure the Azure resource infrastructure.</returns>
public static Action<AzureResourceInfrastructure> GetInfrastructureConfigurationAction(
this IResourceBuilder<IDaprComponentResource> builder,
ContainerAppManagedEnvironmentDaprComponent daprComponent,
IEnumerable<ProvisioningParameter>? parameters = null, bool? requireScopes = false) =>
(AzureResourceInfrastructure infrastructure) =>
{
ArgumentNullException.ThrowIfNull(daprComponent, nameof(daprComponent));
ArgumentNullException.ThrowIfNull(infrastructure, nameof(infrastructure));

ProvisioningVariable resourceToken = new("resourceToken", typeof(string))
{
Value = BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)
};

infrastructure.Add(resourceToken);

var containerAppEnvironment = ContainerAppManagedEnvironment.FromExisting("containerAppEnvironment");
containerAppEnvironment.Name = BicepFunction.Interpolate($"cae-{resourceToken}");

infrastructure.Add(containerAppEnvironment);
daprComponent.Parent = containerAppEnvironment;


if (requireScopes == true)
{
builder.AddScopes(daprComponent);
}
infrastructure.Add(daprComponent);

foreach (var parameter in parameters ?? [])
{
infrastructure.Add(parameter);
}
};

/// <summary>
/// Adds scopes to the specified Dapr component in a container app managed environment.
/// </summary>
Expand All @@ -114,11 +46,11 @@ public static Action<AzureResourceInfrastructure> GetInfrastructureConfiguration
public static void AddScopes(this IResourceBuilder<IDaprComponentResource> builder, ContainerAppManagedEnvironmentDaprComponent daprComponent)
{
daprComponent.Scopes = [];

foreach (var resource in builder.ApplicationBuilder.Resources)
{

if (!resource.TryGetLastAnnotation<DaprSidecarAnnotation>(out var daprAnnotation) ||
!resource.TryGetAnnotationsOfType<DaprComponentReferenceAnnotation>(out var daprComponentReferenceAnnotations))
!daprAnnotation.Sidecar.TryGetAnnotationsOfType<DaprComponentReferenceAnnotation>(out var daprComponentReferenceAnnotations))
{
continue;
}
Expand All @@ -135,13 +67,10 @@ public static void AddScopes(this IResourceBuilder<IDaprComponentResource> build
var appId = sidecarOptions?.AppId ?? resource.Name;
daprComponent.Scopes.Add(appId);
}

}
}
}



/// <summary>
/// Creates a new Dapr component for a container app managed environment.
/// </summary>
Expand Down

This file was deleted.

Loading
Loading