Skip to content

Commit

Permalink
Update README.md with DI content (#21410)
Browse files Browse the repository at this point in the history
* Update README.md

adding dependency injection section

* Update README.md

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.

* Update README.md

Change the method named used and show the configuration snippet as well.

* Update sdk/servicebus/Azure.Messaging.ServiceBus/README.md

Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>

* Update sdk/servicebus/Azure.Messaging.ServiceBus/README.md

Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>

* minor edits

Co-authored-by: Alex Ghiondea <AlexGhiondea@users.noreply.github.com>
Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 4, 2021
1 parent aa88d39 commit f581362
Showing 1 changed file with 28 additions and 0 deletions.
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
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

0 comments on commit f581362

Please sign in to comment.