-
Notifications
You must be signed in to change notification settings - Fork 462
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
[release/8.0-preview2] Added support for adding connection strings to non-resources #1352
[release/8.0-preview2] Added support for adding connection strings to non-resources #1352
Conversation
… new ConnectionString type that lets users specify the connection string name and an optional value. If there's no value then lookup happens based on the connection string name via configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2 comments can be made in main
, we don't have to block the backport PR for them.
LGTM.
var connectionStringName = $"{ConnectionStringEnvironmentName}{connectionString.Name}"; | ||
|
||
return builder.WithEnvironment(context => | ||
{ | ||
var connectionStringValue = connectionString.Value ?? | ||
builder.ApplicationBuilder.Configuration.GetConnectionString(connectionString.Name); | ||
|
||
if (string.IsNullOrEmpty(connectionStringValue)) | ||
{ | ||
throw new DistributedApplicationException($"A connection string for '{connectionString.Name}' could not be retrieved."); | ||
} | ||
|
||
if (builder.Resource is ContainerResource) | ||
{ | ||
connectionStringValue = HostNameResolver.ReplaceLocalhostWithContainerHost(connectionStringValue, builder.ApplicationBuilder.Configuration); | ||
} | ||
|
||
context.EnvironmentVariables[connectionStringName] = connectionStringValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var connectionStringName = $"{ConnectionStringEnvironmentName}{connectionString.Name}"; | |
return builder.WithEnvironment(context => | |
{ | |
var connectionStringValue = connectionString.Value ?? | |
builder.ApplicationBuilder.Configuration.GetConnectionString(connectionString.Name); | |
if (string.IsNullOrEmpty(connectionStringValue)) | |
{ | |
throw new DistributedApplicationException($"A connection string for '{connectionString.Name}' could not be retrieved."); | |
} | |
if (builder.Resource is ContainerResource) | |
{ | |
connectionStringValue = HostNameResolver.ReplaceLocalhostWithContainerHost(connectionStringValue, builder.ApplicationBuilder.Configuration); | |
} | |
context.EnvironmentVariables[connectionStringName] = connectionStringValue; | |
return builder.WithEnvironment(context => | |
{ | |
var connectionStringValue = connectionString.Value ?? | |
builder.ApplicationBuilder.Configuration.GetConnectionString(connectionString.Name); | |
if (string.IsNullOrEmpty(connectionStringValue)) | |
{ | |
throw new DistributedApplicationException($"A connection string for '{connectionString.Name}' could not be retrieved."); | |
} | |
if (builder.Resource is ContainerResource) | |
{ | |
connectionStringValue = HostNameResolver.ReplaceLocalhostWithContainerHost(connectionStringValue, builder.ApplicationBuilder.Configuration); | |
} | |
context.EnvironmentVariables[$"{ConnectionStringEnvironmentName}{connectionString.Name}"] = connectionStringValue; |
You are already capturing connectionString
into the lambda, so you might as well make this name in the lambda instead of making the capture object bigger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to have the exact same code in main and preview2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said above "My 2 comments can be made in main, we don't have to block the backport PR for them.".
Co-authored-by: Eric Erhardt <[email protected]>
Backport of #1350 to release/8.0-preview2
/cc @mitchdenny @davidfowl
Customer Impact
Testing
Risk
IMPORTANT: If this backport is for a servicing release, please verify that:
The PR target branch is
release/X.0-staging
, notrelease/X.0
.If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.
Microsoft Reviewers: Open in CodeFlow