Skip to content

Commit

Permalink
Move code around
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed Feb 7, 2025
1 parent 02dc07b commit a38eae4
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(this IResou
.AddAzureStorage($"{builder.Resource.Name}-storage")
.WithParentRelationship(builder.Resource);

var lifetime = ContainerLifetime.Session;

// Copy the lifetime from the main resource to the storage resource

if (configureContainer != null)
{
var surrogate = new AzureEventHubsEmulatorResource(builder.Resource);
var surrogateBuilder = builder.ApplicationBuilder.CreateResourceBuilder(surrogate);
configureContainer(surrogateBuilder);

if (surrogate.TryGetLastAnnotation<ContainerLifetimeAnnotation>(out var lifetimeAnnotation))
{
lifetime = lifetimeAnnotation.Lifetime;
}
}

storageResource = storageResource.RunAsEmulator(c => c.WithLifetime(lifetime));

var storage = storageResource.Resource;

builder.WithAnnotation(new EnvironmentCallbackAnnotation((EnvironmentCallbackContext context) =>
Expand Down Expand Up @@ -256,24 +274,6 @@ public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(this IResou

builder.WithHealthCheck(healthCheckKey);

var lifetime = ContainerLifetime.Session;

// Copy the lifetime from the main resource to the storage resource

if (configureContainer != null)
{
var surrogate = new AzureEventHubsEmulatorResource(builder.Resource);
var surrogateBuilder = builder.ApplicationBuilder.CreateResourceBuilder(surrogate);
configureContainer(surrogateBuilder);

if (surrogate.TryGetLastAnnotation<ContainerLifetimeAnnotation>(out var lifetimeAnnotation))
{
lifetime = lifetimeAnnotation.Lifetime;
}
}

storageResource = storageResource.RunAsEmulator(c => c.WithLifetime(lifetime));

// RunAsEmulator() can be followed by custom model configuration so we need to delay the creation of the Config.json file
// until all resources are about to be prepared and annotations can't be updated anymore.

Expand Down

0 comments on commit a38eae4

Please sign in to comment.