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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sdk/servicebus/Azure.Messaging.ServiceBus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ ServiceBusClient client = new ServiceBusClient(connectionString);

To see how to authenticate using Azure.Identity, view this [example](#authenticating-with-azureidentity).

### ASP.NET Core

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.

public void ConfigureServices(IServiceCollection services)
{
services.AddAzureClients(builder =>
{
builder.AddServiceBusClient(Configuration.GetConnectionString("ServiceBus"));
});

services.AddControllers();
}
```

To use the preceding code, add this to your configuration:

```json
{
"ConnectionStrings": {
"ServiceBus": "<connection_string>"
}
}
```

For more details, see [Dependency injection with the Azure SDK for .NET](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection).

## Key concepts

Once you've initialized a `ServiceBusClient`, you can interact with the primary resource types within a Service Bus Namespace, of which multiple can exist and on which actual message transmission takes place, the namespace often serving as an application container:
Expand Down