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

Update README.md with DI content #21410

Merged
merged 6 commits into from
Jun 4, 2021
Merged

Update README.md with DI content #21410

merged 6 commits into from
Jun 4, 2021

Conversation

lilyjma
Copy link
Contributor

@lilyjma lilyjma commented May 27, 2021

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.

  • Please open PR in Draft mode if it is:
    • Work in progress or not intended to be merged.
    • Encountering multiple pipeline failures and working on fixes.
  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • I have read the contribution guidelines.
  • The pull request does not introduce breaking changes.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code. (Track 2 only)
  • The *.csproj and AssemblyInfo.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] or Azure.ResourceManager.[RP]

  • Include updated management metadata.
  • Update AzureRP.props to add/remove version info to maintain up to date API versions.

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:

    • Do not modify any code in generated folders.
    • Do not selectively include/remove generated files in the PR.
    • Do use generate.ps1/cmd to generate this PR instead of calling autorest 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:

      `dotnet msbuild eng/mgmt.proj /t:Util /p:UtilityName=InstallPsModules`
    

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.

adding dependency injection section
Copy link
Member

@scottaddie scottaddie left a 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.

sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
sdk/servicebus/Azure.Messaging.ServiceBus/README.md Outdated Show resolved Hide resolved
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"]);
Copy link
Member

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?

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 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.

Copy link
Member

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"));

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor

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?

Copy link
Member

@KrzysztofCwalina KrzysztofCwalina Jun 1, 2021

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.

Copy link
Contributor

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.

Copy link
Member

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?

AlexGhiondea and others added 4 commits May 27, 2021 17:00
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>
Copy link
Member

@scottaddie scottaddie left a comment

Choose a reason for hiding this comment

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

:shipit:

@lilyjma lilyjma marked this pull request as ready for review May 28, 2021 19:37
@lilyjma lilyjma requested a review from jsquire as a code owner May 28, 2021 19:37
@lilyjma lilyjma changed the title Update README.md Update README.md with DI content May 28, 2021

To inject `ServiceBusClient` as a dependency in an ASP.NET Core app, register the client in the `Startup.ConfigureServices` method:

```csharp
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@jsquire
Copy link
Member

jsquire commented Jun 4, 2021

/azp run net - servicebus - ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lilyjma lilyjma merged commit f581362 into master Jun 4, 2021
@lilyjma lilyjma deleted the lilyjma-patch-1 branch June 4, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants