-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update README.md with DI content #21410
Conversation
adding dependency injection section
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.
Nice work, Lily! Here are some suggestions to consider.
Proposing changes based on the chat with @KrzysztofCwalina and @davidfowl. The changes are around simplifying the samples and using the configuration instead of the hard coded connection string.
{ | ||
services.AddAzureClients(builder => | ||
{ | ||
builder.AddServiceBusClient(Configuration["connection_string_key"]); |
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.
@AlexGhiondea Should we use Configuration.GetConnectionString("connection_string_key")
instead?
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 think GetConnectionString assumes that the config includes a "ConnectionStrings" setting. We should probably include what the config looks like to go along with the code used.
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.
That's correct. We could use a config like this:
{
"ConnectionStrings": {
"ServiceBus": "<connection_string>"
}
}
Then the Service Bus client registration line becomes:
builder.AddServiceBusClient(Configuration.GetConnectionString("ServiceBus"));
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 agree showing the config json is a good idea. For some reason @davidfowl did not want to use .GetConnectionString and instead wanted the indexer. David, why?
If a service supports AzureKeyCredential, the DI sample should use it instead of using the connection string. The type allows for rotating keys. I am fine with merging this as-is, but I would prefer if we filed and issue to update the sample later to use AzureKeyCredential.
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.
@pakrym, @JoshLove-msft, I noticed the DI extension method for servicebus works only with connection strings and not with AzureKeyCredential. Do we not support rotating the keys at runtime?
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.
With respect to key rotation and such, it feels like we're getting too deep for the README if we start including that level of detail. Perhaps we should just ensure that we have a sample dedicated to that concept and link to that from the README?
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 agree with Jesse, we should have a more advanced sample of rolling AzureNamedKeyCredential but I don't think it should be in the main readme.
Do we have examples of rolling AzureNamedKeyCredential
without DI?
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.
With respect to key rotation and such, it feels like we're getting too deep for the README if we start including that level of detail. Perhaps we should just ensure that we have a sample dedicated to that concept and link to that from the README?
@jsquire, @pakrym, my point was that once we start pushing people toward DI, we need to explain how do do various things that are not very obvious when using DI. For example, changing a ctor-using sample to key rotation is something developers should be able to do on their own (if they understand basics of key rotation). Changing DI sample to key rotation is at least non-trivial if not outright impossible/impractical.
Also, I did not say we need it in the main readme. I don't think the main readme should have any DI samples. I think it should have a link to a proper DI document.
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 point was that once we start pushing people toward DI, we need to explain how do do various things that are not very obvious when using DI.
Agreed.
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.
Do we have examples of rolling
AzureNamedKeyCredential
without DI?
I don't know that we do. We have examples of using it with clients, but not explicitly rotating. Likewise for the AzureSasCredential
. Since those are Core types, it may be helpful to centralize the rotation sample and link to them from the service examples of using them with clients. Thoughts?
Change the method named used and show the configuration snippet as well.
Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
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.
|
||
To inject `ServiceBusClient` as a dependency in an ASP.NET Core app, register the client in the `Startup.ConfigureServices` method: | ||
|
||
```csharp |
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 believe we'll want this content to be a snippet to ensure that we remain up-to-date and compliable. I If we're doing this for multiple services, I wonder if it makes sense to have an ASP.NET sample under the repository root samples
directory and source all of the snippets from there?
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 think it should be a part of each service's tests/samples as other snippets. We also need to devise a better way to test these extension methods.
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 agree with Pavel. Having this content in each service's readme will at least ensure that we don't miss the extension method for some packages (this was the case for Event Grid). Curious if different Azure SDK clients have different lifetime management needs. This might be another reason for each service to have its own content.
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 wasn't suggesting that we move the README section itself, just the code that we link to as a snippet. This is currently inline, but we'll need to update so that it uses our snippet system so the code is compiled and validated during nightly runs.
The question that I was posing was whether the test for that should live in the suite for each individual service or in some central location since there are dependencies for ASP.NET that would need to be included.
/azp run net - servicebus - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
Adding dependency injection section
(The exact location to place the section is still to be determined - this is just an idea.)
All SDK Contribution checklist:
This checklist is used to make sure that common guidelines for a pull request are followed.
Draft
mode if it is:General Guidelines and Best Practices
Testing Guidelines
SDK Generation Guidelines
*.csproj
andAssemblyInfo.cs
files have been updated with the new version of the SDK. Please double check nuget.org current release version.Additional management plane SDK specific contribution checklist:
Note: Only applies to
Microsoft.Azure.Management.[RP]
orAzure.ResourceManager.[RP]
Management plane SDK Troubleshooting
If this is very first SDK for a services and you are adding new service folders directly under /SDK, please add
new service
label and/or contact assigned reviewer.If the check fails at the
Verify Code Generation
step, please ensure:generate.ps1/cmd
to generate this PR instead of callingautorest
directly.Please pay attention to the @microsoft.csharp version output after running
generate.ps1
. If it is lower than current released version (2.3.82), please run it again as it should pull down the latest version.Note: We have recently updated the PSH module called by
generate.ps1
to emit additional data. This would help reduce/eliminate the Code Verification check error. Please run following command:Old outstanding PR cleanup
Please note:
If PRs (including draft) has been out for more than 60 days and there are no responses from our query or followups, they will be closed to maintain a concise list for our reviewers.