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

Remove ConnectionString on With methods in Hosting App Model #84

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Oct 5, 2023

Instead, add new Add overloads that take a connection string to an existing server.

Note - I needed to make IDistributedApplicationComponentBuilder<out T> an out generic because I need IDistributedApplicationComponentBuilder<PostgresContainerComponent> to also be an IDistributedApplicationComponentBuilder<IPostgresComponent>.

Fix #62

Instead, add new Add overloads that take a connection string to an existing server.

Fix #62
public static IDistributedApplicationComponentBuilder<SqlServerComponent> AddSqlServer(this IDistributedApplicationBuilder builder, string name, string connectionString)
{
return builder.AddComponent(new SqlServerComponent(name, connectionString))
.WithAnnotation(new ManifestPublishingCallbackAnnotation(WriteSqlServerComponentToManifest));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this redis component is being created based on a connection string we need to adjust the manifest writing for components created like this to include a connection string attribute. It should look like this:

{
  "components": {
    "<name>": {
      "type": "redis.v1",
      "connectionString": "<connection string>"
    }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I can make that change. I am a little concerned how the deployment tool is going to decide if this is the real connection string to use, or if it should provision a new one.

I think the main scenario is that the dev wants to use this specific connection string at dev time, but wants something different at publish time.

cc @ellismg - in case you have thoughts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for this to be ambiguous for now. We have this problem with other environment variables as well.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my thinking here is that if the connectionString property is present on a redis.v1 component, we respect it, when you have another component that does a reference like this:

            "env": {
                "ConnectionStrings__redis": "{redis.connectionString}"
            },

And if connectionString is not present in this object in the manifest, then we use the value that would be injected by ACA and their connected services stuff?

Does that make sense? Using the existance of this key in the object to distinguish between "a literal" vs "something that needs to be resolved by the underlying platform"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl - maybe this is where the "DevHost" configuration stuff we talked about this week comes in. The DevHost code would have something like:

builder.AddRedis("cache", builder.Configuration.GetConnectionString("redisConnection"));

And then in DevHost\appsettings.Development.json (or user secrets):

{
  "ConnectionStrings": {
    "redisConnection": "localhost:6379"
  }
}

So when you F5 / dotnet run locally, you get a connection to localhost:6379.

Then at "manifest" generation time, you don't define ConnectionStrings:redisConnection, which means the above will return null, and that will mean "I want a new resource created for me for this".

@mitchdenny
Copy link
Member

This looks good. I'm not sure about GetConnectionString(...) but given where we are right now it's probably the best option.

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending comment around manifest generation.

@eerhardt eerhardt enabled auto-merge (squash) October 6, 2023 18:50
- Write the connectionString to the manifest if it is provided.
- Use DistributedApplicationException
@eerhardt eerhardt merged commit 6b96c3a into main Oct 6, 2023
4 checks passed
@eerhardt eerhardt deleted the RemoveConnectionFromWith branch October 6, 2023 19:53
@danmoseley danmoseley added the area-integrations Issues pertaining to Aspire Integrations packages label Nov 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove With methods that take a connection string
5 participants