-
Notifications
You must be signed in to change notification settings - Fork 816
Open
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Intuitively I'd think that this should be possible:
var test = builder.AddContainer("test", "caddy")
.WithHttpEndpoint(targetPort: 80);
var api = builder.AddProject<Projects.ApiService>("apiservice")
.WithReference(test);but it is not. Leaving out the reference compiles, but the ApiService will not be able to call the container like
builder.Services.AddHttpClient("test", client =>
{
client.BaseAddress = new("http://test");
});
//...
await client.GetStringAsync("/"); //cannot connect to host "test"I need to do a workaround like
public static class AspireBuilderExtensions
{
public static IResourceBuilder<ContainerServiceResource> AddContainerService(this IDistributedApplicationBuilder builder, [ResourceName] string name, string? image = null, string? tag = null)
{
var res = new ContainerServiceResource(name);
var service = builder.AddResource(res);
if (image is not null)
service.WithImage(image, tag);
return service;
}
}
public class ContainerServiceResource : ContainerResource, IResourceWithServiceDiscovery
{
public ContainerServiceResource(string name, string? entrypoint = null) : base(name, entrypoint)
{
}
}
// ...
var test = builder.AddContainerService("test", "caddy")
.WithHttpEndpoint(targetPort: 80);
var api = builder.AddProject<Projects.ApiService>("apiservice")
.WithReference(test);and then I can successfully call the container.
Describe the solution you'd like
ContainerResource should inherit IResourceWithServiceDiscovery by default, or make it so after adding an endpoint this works:
var test = builder.AddContainer("test", "caddy")
.WithHttpEndpoint(targetPort: 80);
var api = builder.AddProject<Projects.ApiService>("apiservice")
.WithReference(test);Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication