Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for expressing existing external HTTP services as resources in the hosting project #775

Closed
DamianEdwards opened this issue Nov 11, 2023 · 6 comments · Fixed by #1030
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication help wanted Issue that is a good candidate for community contribution.

Comments

@DamianEdwards
Copy link
Member

DamianEdwards commented Nov 11, 2023

Scenario is I have an external HTTP service that I want to connect to (similar to an existing Redis instance or existing PostgreSQL instance) so I want to model it in my hosting project so that other resources can reference it and have service discovery configured so they can refer to it by the name I give it.

e.g.
MyApp.AppHost/Program.cs

var builder = DistributedApplication.CreateBuilder(args);

var weatherApi = builder.AddHttpService("weatherapi", "http://weather.internal.sda76erh.us.contoso.com");

builder.AddProject<Projects.Frontend>("frontend")
    .WithReference(weatherApi);

builder.Build().Run();

MyApp.Frontend/Program.cs

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddHttpClient("weather", c => c.BaseAddress = new("http://weatherapi"));

var app = builder.Build();

app.MapGet("/", async (IHttpClientFactory hcf) => await hcf.CreateClient("weather").GetStringAsync("/weatherforecast"));

app.MapDefaultEndpoints();

app.Run();
@DamianEdwards DamianEdwards added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 11, 2023
@DamianEdwards DamianEdwards changed the title Add support for expressing existing external HTTP services as resources in the hosting projects Add support for expressing existing external HTTP services as resources in the hosting project Nov 11, 2023
@davidfowl davidfowl added this to the preview 2 (Dec) milestone Nov 20, 2023
@davidfowl davidfowl added the help wanted Issue that is a good candidate for community contribution. label Nov 20, 2023
@Kahbazi
Copy link
Member

Kahbazi commented Nov 20, 2023

I'm interested in sending a PR for this issue. Could you assign this to me please?

These are the steps that I know that has to be done

  • Add new APIs which adds HttpService in IDistributedApplicationBuilder.Resources.
  • Write the resource in ManifestPublisher with ManifestPublishingCallbackAnnotation.
  • Somehow make the Service Discovery works (I haven't figure this out yet!)

BTW the description for 'help wanted' label seems wrong!

@DamianEdwards
Copy link
Member Author

DamianEdwards commented Nov 20, 2023

@Kahbazi that'd be great! For service discovery the resource needs to have a ServiceBindingAnnotation added that describes the details. We'd love to include this in preview.2 if you're able to contribute this within the next two weeks. Please let us know if you need any other help.

I think for the appmodel and manifest this is a new resource type, e.g. httpservice.v0. Thoughts @mitchdenny @davidfowl?

Should we have an extension method explicitly for gRPC services too, that add the HTTP/2 flag, e.g. builder.AddGrpcService("weatherapi", "http://weather.internal.sda76erh.us.contoso.com");, that just uses the same resource type?

@mitchdenny
Copy link
Member

We'd probably want this to behave more like something that participates in service discovery than a connection string.

@DamianEdwards
Copy link
Member Author

We'd probably want this to behave more like something that participates in service discovery than a connection string.

Right, is that not what adding a ServiceBindingAnnotation does?

@Kahbazi
Copy link
Member

Kahbazi commented Nov 21, 2023

@DamianEdwards Is there any API Review process for this project or I just add the APIs that I think is needed and we would discuss them in the PR? I will send a draft PR before the weekend to make sure that this could be in preview 2.

@DamianEdwards
Copy link
Member Author

@Kahbazi send the PR and we can discuss there, thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication help wanted Issue that is a good candidate for community contribution.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants