I am trying to learn Aspire, but I have problems in understanding what are it’s advantages for production and how to use it outside local environment. To give a summary of my current understanding:
General: Basically Aspire is just 2 new projects (AppHost and ServiceDefaults) that binds other projects, providing different features (Service Discovery, Telemetry, Components).
For Local I see it like a docker compose on steroids. In AppHost you just configure the relations between services and external components (e.g. Redis), then you can do calls from one service to another one using a natural name, without carrying about ports. To start the application, you will start AppHost project, that will do all the work providing a nice dashboard with different functionalities. Played a little bit with it and I love it.
For Production/Testing/Staging environments: Asumming that I want to use Kubernetes with Dockerize apps. If I correctly understand, AppHost and ServiceDefaults projects will not be deployed. Then except the components part of the Aspire, I don’t really see the advantages, cause the orchestration will be made by Kubernetes.
QUESTION PART:
If what I described above is true, I have problems understanding how will the apps correctly run without being orchestrated by AppHost? There are 2 situations:
Calling another service:
builder.Services.AddHttpClient<WeatherApiClient>(client =>
{
client.BaseAddress = new("https+http://weatherservice");
});
This will break when not on local, because https+http://weatherservice is not a valid URL if not orchestrated by Aspire.
Using components:
builder.AddRedisOutputCache("cache");
When I will inject the IDistributedCache outside Aspire context, I will get an error, cause I don’t provide any connection string.
Current solution:
The option that I found (but I don’t know if is the best or if even I should have those issues) is to have an appsettings.Aspire.json that will contains only the names of the services and will be used when running locally from AppHost. In order to use it I set the environment something like this:
var apiService = builder.AddProject<Projects.AspireTest_ApiService>("apiservice")
.WithReference(airQualityService)
.WithReference(cache)
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Aspire");
Now if I want to run the projects independently or to run it in Kubernetes, I will just provide a separate appsetting file that will be used. Something like:
{
"AirQualityUrl": http://somevalidUrl",
"Aspire": {
"StackExchange": {
"Redis": {
"ConnectionString": "127.0.0.1:6379"
}
}
}
}
So the api part is covered by the fact that when initializing the HttpClient, I will pick the values from appsetings (so for Aspire will be https+http://airqualityapi and for other envs will be http://somevalidUrl
For the component part it looks like if I overwrite Aspire:StackExchange:Redis:ConnectionString key, it will take the settings from there.
I am sorry for the long question. Is my understanding of Aspire and the solution that I found for deployment ok?