Skip to content

Commit 3ebd577

Browse files
committed
Using the new event callback model
1 parent 91cddc3 commit 3ebd577

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ private static IResourceBuilder<T> WithJolokiaHealthCheck<T>(
154154
const int statusCode = 200;
155155
const string endpointName = "web";
156156
const string scheme = "http";
157-
EndpointReference endpoint = builder.Resource.GetEndpoint(endpointName);
158157

159-
builder.ApplicationBuilder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>((_, _) =>
158+
builder.OnResourceEndpointsAllocated((resource, @event, ct) =>
160159
{
160+
var endpoint = resource.GetEndpoint(endpointName);
161161
if (!endpoint.Exists)
162162
{
163163
throw new DistributedApplicationException($"The endpoint '{endpointName}' does not exist on the resource '{builder.Resource.Name}'.");
@@ -173,11 +173,12 @@ private static IResourceBuilder<T> WithJolokiaHealthCheck<T>(
173173

174174
Uri? uri = null;
175175
string basicAuthentication = string.Empty;
176-
builder.ApplicationBuilder.Eventing.Subscribe<BeforeResourceStartedEvent>(builder.Resource, async (_, ct) =>
176+
builder.OnBeforeResourceStarted(async (resource, _, ct) =>
177177
{
178+
var endpoint = resource.GetEndpoint(endpointName);
178179
Uri baseUri = new (endpoint.Url, UriKind.Absolute);
179-
string userName = (await builder.Resource.UserNameReference.GetValueAsync(ct))!;
180-
string password = (await builder.Resource.PasswordParameter.GetValueAsync(ct))!;
180+
string userName = (await resource.UserNameReference.GetValueAsync(ct))!;
181+
string password = (await resource.PasswordParameter.GetValueAsync(ct))!;
181182
basicAuthentication = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{userName}:{password}"));
182183
uri = new UriBuilder(baseUri)
183184
{

src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static IResourceBuilder<NgrokResource> AddNgrok(
3434
ArgumentNullException.ThrowIfNull(builder);
3535
if (configurationFolder is not null)
3636
ArgumentException.ThrowIfNullOrWhiteSpace(configurationFolder);
37-
37+
3838
if (endpointPort is not null)
3939
{
4040
ArgumentOutOfRangeException.ThrowIfLessThan(endpointPort.Value, 1, nameof(endpointPort));
@@ -49,28 +49,27 @@ public static IResourceBuilder<NgrokResource> AddNgrok(
4949
configurationFolder ??= Path.Combine(builder.AppHostDirectory, ".ngrok");
5050
if (!Directory.Exists(configurationFolder))
5151
Directory.CreateDirectory(configurationFolder);
52-
53-
var resource = new NgrokResource(name);
54-
var resourceBuilder = builder.AddResource(resource)
52+
53+
var resourceBuilder = builder.AddResource(new NgrokResource(name))
5554
.WithImage(NgrokContainerValues.Image, NgrokContainerValues.Tag)
5655
.WithImageRegistry(NgrokContainerValues.Registry)
5756
.WithBindMount(configurationFolder, "/var/tmp/ngrok")
5857
.WithHttpEndpoint(targetPort: 4040, port: endpointPort, name: endpointName);
59-
builder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>(async (e, ct) =>
58+
resourceBuilder.OnResourceEndpointsAllocated(async (resource, e, ct) =>
6059
{
6160
var endpointTuples = resource.Annotations
6261
.OfType<NgrokEndpointAnnotation>()
6362
.SelectMany(annotation => annotation.Endpoints.Select(ngrokEndpoint => (endpointRefernce: annotation.Resource.GetEndpoint(ngrokEndpoint.EndpointName), ngrokEndpoint)))
6463
.ToList();
6564
await CreateNgrokConfigurationFileAsync(configurationFolder, name, endpointTuples, configurationVersion ?? 3);
66-
65+
6766
resourceBuilder.WithArgs(
68-
"start", endpointTuples.Count > 0 ? "--all" : "--none",
67+
"start", endpointTuples.Count > 0 ? "--all" : "--none",
6968
"--config", $"/var/tmp/ngrok/{name}.yml");
7069
});
7170
return resourceBuilder;
7271
}
73-
72+
7473
/// <summary>
7574
/// Adds a ngrok auth token to a ngrok resource.
7675
/// </summary>
@@ -86,7 +85,7 @@ public static IResourceBuilder<NgrokResource> WithAuthToken(
8685

8786
return builder.WithEnvironment(NgrokContainerValues.AuthTokenEnvName, ngrokAuthToken);
8887
}
89-
88+
9089
/// <summary>
9190
/// Adds a ngrok auth token to a ngrok resource.
9291
/// </summary>
@@ -102,13 +101,13 @@ public static IResourceBuilder<NgrokResource> WithAuthToken(
102101

103102
return builder.WithEnvironment(NgrokContainerValues.AuthTokenEnvName, ngrokAuthToken);
104103
}
105-
104+
106105
/// <summary>
107106
/// Configures a resource with endpoints as a ngrok tunnel endpoint.
108107
/// </summary>
109108
/// <typeparam name="TResource">The resource type.</typeparam>
110109
public static IResourceBuilder<NgrokResource> WithTunnelEndpoint<TResource>(
111-
this IResourceBuilder<NgrokResource> builder,
110+
this IResourceBuilder<NgrokResource> builder,
112111
IResourceBuilder<TResource> resource,
113112
string endpointName,
114113
string? ngrokUrl = null,
@@ -136,7 +135,7 @@ public static IResourceBuilder<NgrokResource> WithTunnelEndpoint<TResource>(
136135

137136
return builder;
138137
}
139-
138+
140139
private static async Task CreateNgrokConfigurationFileAsync(
141140
string configurationFolder,
142141
string name,
@@ -165,7 +164,7 @@ private static async Task CreateNgrokConfigurationFileAsync(
165164
break;
166165
case 3:
167166
ngrokConfig.AppendLine("agent:");
168-
ngrokConfig.AppendLine( " log: stdout");
167+
ngrokConfig.AppendLine(" log: stdout");
169168
if (endpointTuples.Count > 0)
170169
{
171170
ngrokConfig.AppendLine();
@@ -190,7 +189,7 @@ private static async Task CreateNgrokConfigurationFileAsync(
190189
private static string GetUpstreamUrl(EndpointReference endpoint)
191190
{
192191
var isLocal = endpoint.Host.Equals("localhost", StringComparison.InvariantCultureIgnoreCase);
193-
var host = (IsWindows || IsOsx) && isLocal? "host.docker.internal" : endpoint.Host;
192+
var host = (IsWindows || IsOsx) && isLocal ? "host.docker.internal" : endpoint.Host;
194193
return $"{endpoint.Scheme}://{host}:{endpoint.Port}";
195194
}
196195
}

tests/CommunityToolkit.Aspire.Hosting.Adminer.Tests/AddAdminerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public async Task AddAdminerWithDefaultsAddsUrlAnnotations()
301301
var adminer = builder.AddAdminer("adminer");
302302

303303
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
304-
builder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>((e, ct) =>
304+
adminer.OnResourceEndpointsAllocated((resource, @event, ct) =>
305305
{
306306
tcs.SetResult();
307307
return Task.CompletedTask;

tests/CommunityToolkit.Aspire.Hosting.DbGate.Tests/AddDbGateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public async Task AddDbGateWithDefaultsAddsUrlAnnotations()
564564
var dbgate = builder.AddDbGate("dbgate");
565565

566566
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
567-
builder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>((e, ct) =>
567+
dbgate.OnResourceEndpointsAllocated((resource, @event, ct) =>
568568
{
569569
tcs.SetResult();
570570
return Task.CompletedTask;

0 commit comments

Comments
 (0)