Skip to content

Commit f4efb6c

Browse files
authored
Refactor connection string handling in resource classes (#212)
Removed the `GetConnectionString` method from `TemporalServerExecutableResource` and `TemporalServerContainerResource`. Updated the `ConnectionStringExpression` property in both classes to directly use the `GetEndpoint` method with the "server" endpoint and `EndpointProperty.HostAndPort`. This simplifies the code, reduces redundancy, and improves maintainability.
1 parent 844ca9a commit f4efb6c

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

src/InfinityFlow.Aspire.Temporal/TemporalServerExecutableResource.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,12 @@ namespace Aspire.Hosting;
66

77
public class TemporalServerExecutableResource(string name, TemporalServerResourceArguments arguments) : ExecutableResource(name, command: "temporal", workingDirectory: ""), IResourceWithConnectionString
88
{
9-
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create($"{GetConnectionString()}");
10-
11-
public string? GetConnectionString()
12-
{
13-
var endpoints = this.GetEndpoints().Where(e => e.IsAllocated).ToList();
14-
if (endpoints.Count==0)
15-
{
16-
return null;
17-
}
18-
19-
var server = endpoints.SingleOrDefault(x => x.EndpointName == "server");
20-
21-
return $"{server?.Host}:{server?.Port}";
22-
}
9+
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create($"{this.GetEndpoint("server").Property(EndpointProperty.HostAndPort)}");
2310
}
2411

2512
public class TemporalServerContainerResource(string name, TemporalServerResourceArguments arguments) : ContainerResource(name,entrypoint: "/temporal"), IResourceWithConnectionString, IResourceWithEnvironment
2613
{
27-
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create($"{GetConnectionString()}");
14+
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create($"{this.GetEndpoint("server").Property(EndpointProperty.HostAndPort)}");
2815

2916
public TemporalServerResourceArguments Arguments { get; } = arguments;
30-
31-
public string? GetConnectionString()
32-
{
33-
var endpoints = this.GetEndpoints().Where(e => e.IsAllocated).ToList();
34-
if (endpoints.Count == 0)
35-
{
36-
return null;
37-
}
38-
39-
var server = endpoints.SingleOrDefault(x => x.EndpointName == "server");
40-
41-
return $"{server?.Host}:{server?.Port}";
42-
}
4317
}

0 commit comments

Comments
 (0)