-
Notifications
You must be signed in to change notification settings - Fork 35
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
Allow passing a "connectionString key" as well as a full connectionstring on all setup overloads #541
Comments
Hi @julealgon, thanks for the suggestion! That makes sense, and I'm open to the idea of pulling the connection string based on the key. I'm just thinking about whether this might be confusing on first glance since nothing explicitly changes about the parameter name or type, and the method is the same, but it has 2 functionalities. The parameter name is |
@amerjusupovic the confusion aspect is indeed totally valid. I understand this can be weird since it would be "kinda like" an overload, but not really since it has to deal with the same type I guess the only additional comments I can make here would be that EntityFramework Classic used to support something like this in the past: you could either provide the name of a ConnectionString key, or the connection string itself to the dbcontext: EFCore also has this "alternative syntax" where you specify the connection string key name as if it were a connectionstring property, like: services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection")); Maybe that same design/principle could be applied here, considering we are talking about the exact same type of data (a connectionString)? I think that would, at the very least, increase consistency in the .NET ecosystem, even if the system itself is slighly convoluted (I'd honestly rather have This more specific article also mentions the If the team feels umconfortable with the "magical" nature of these calls, perhaps some sort of builder.Configuration
.AddAzureAppConfiguration(c => c.WithConnectionStringKey("AzureAppConfiguration"))
.AddAzureAppConfiguration(c => c.WithConnectionStringKey("AzureAppConfiguration-Common")); It's tough to suggest anything different with the 2 concepts being represented by the I'm not opposed to having native types to represent those 2 things but I do understand that would be a larger, potentiall framework-wide effort. A design with dedicated strong types for each could allow one to overload the operation even if implicit conversion operators from public static IConfigurationBuilder AddAzureAppConfiguration(
this IConfigurationBuilder configurationBuilder,
ConnectionString connectionString)
public static IConfigurationBuilder AddAzureAppConfiguration(
this IConfigurationBuilder configurationBuilder,
ConfigurationKey configurationKey) Assuming both builder.Configuration
.AddAzureAppConfiguration(configurationKey: "AzureAppConfiguration")
.AddAzureAppConfiguration(connectionString: "Endpoint=https://common.azconfig.io;Id=myId;Secret=superSecret"); This would give us the same feel of "2 overloads on string" while still being 100% explicit because of the argument name. |
@julealgon First off, I really appreciate you explaining the different options in your last comment. From discussions I've had so far with those involved in this repo, we don't feel great about the options mainly because the problem we're solving is already an established pattern to get connection strings from configuration. I can understand wanting to make the code a bit shorter, but some of these options add some extra code to write too, as you mentioned. The option of passing in a key with Overall, the sentiment I've gotten is to leave it as is for now. Let me know if there's anything else we should consider. |
This is understandable. In a sense, it is a bit unfortunate when something less-than-ideal becomes so "invasive" that it is hard to move away from it. And the only reason I state "less-than-ideal" is because the vast majority of the time, the intent is to grab the value from configuration, and that option is not "modeled" in the existing API.
Right. But do notice that the options where there are extra methods/extensions/etc still require less logic than the original version, even if they are comparable in length codewise. I think this is actually significant: being slightly verbose is not a big deal, but forcing more logic into the consumer is (in most cases).
I agree here... the
That's obviously fair, I just try to avoid creating variables just for the sake of "looks" in general as variables introduce unneeded state that can by itself introduce other problems later. Code with more state is more error prone in general. I try to reserve variable extraction for when something is used multiple times, or in cases where the variable adds significant semantic value to the code where having it helps explain what is happening and why.
It's your prerogative, of course. I appreciate you taking the suggestion, but for now I don't have anything else to propose. From what I've shown above I'd actually like if the team went with the last option where we had stronger types to represent some of these concepts, which opens the door for stronger patterns without them feeling out of place (like the "2 overloads on Anyways, feel free to close this if the team has decided not to approach it for now. |
@amerjusupovic you might want to use the "closed as not planned" instead of "closed as completed" mode to avoid giving the impression that this was actually implemented to folks going through the issues later. |
When configuring the provider, we currently have to pass the full connection string value. This can become fairly verbose:
Instead, I'd like to propose that every method that takes in a connection string value, also accepts just the key to the connection string in configuration. Calls would look like this using the same code as above:
The implementation would then check whether there are connectionstrings with the value as a key, and if not, try using the value directly as the connection string.
The text was updated successfully, but these errors were encountered: