From 8f25c49f26097013a1e40af348c5cb1a7b56a76a Mon Sep 17 00:00:00 2001 From: lilyjma Date: Thu, 27 May 2021 09:46:45 -0700 Subject: [PATCH 1/6] Update README.md adding dependency injection section --- .../Azure.Messaging.ServiceBus/README.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index 32aa68f0ca882..f1d62077afb7a 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -56,6 +56,36 @@ ServiceBusClient client = new ServiceBusClient(connectionString); To see how to authenticate using Azure.Identity, view this [example](#authenticating-with-azureidentity). +### Dependency Injection + +To inject ServiceBusClient as a dependency in an ASP .NET Core app, you can register the client in the `Startup.ConfigureServices` method in `Startup.cs`: +```C# +public void ConfigureServices(IServiceCollection services) +{ + services.AddAzureClients(builder => + { + builder.AddServiceBusClient(""); + }); + + services.AddControllers(); +} +``` +With the service configured, you can now inject the client as dependency. For example, if you have a `MyApiController` class that needs to use the `ServiceBusClient`: +```C# +public class MyApiController : ControllerBase +{ + private readonly ServiceBusClient _serviceBusClient; + + public MyApiController(ServiceBusClient serviceBusClient) + { + _serviceBusClient = serviceBusClient; + } + + // code that uses ServiceBusClient +} +``` +For more details, see [Dependency injection with the Azure .NET SDK](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: From 9f3bbff88061afe0e3a9167225dacb35098078ca Mon Sep 17 00:00:00 2001 From: Alex Ghiondea Date: Thu, 27 May 2021 13:27:34 -0700 Subject: [PATCH 2/6] 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. --- .../Azure.Messaging.ServiceBus/README.md | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index f1d62077afb7a..28bf1db99b3ed 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -56,7 +56,7 @@ ServiceBusClient client = new ServiceBusClient(connectionString); To see how to authenticate using Azure.Identity, view this [example](#authenticating-with-azureidentity). -### Dependency Injection +### ASP.NET Core To inject ServiceBusClient as a dependency in an ASP .NET Core app, you can register the client in the `Startup.ConfigureServices` method in `Startup.cs`: ```C# @@ -64,26 +64,12 @@ public void ConfigureServices(IServiceCollection services) { services.AddAzureClients(builder => { - builder.AddServiceBusClient(""); + builder.AddServiceBusClient(Configuration["connection_string_key"]); }); services.AddControllers(); } ``` -With the service configured, you can now inject the client as dependency. For example, if you have a `MyApiController` class that needs to use the `ServiceBusClient`: -```C# -public class MyApiController : ControllerBase -{ - private readonly ServiceBusClient _serviceBusClient; - - public MyApiController(ServiceBusClient serviceBusClient) - { - _serviceBusClient = serviceBusClient; - } - - // code that uses ServiceBusClient -} -``` For more details, see [Dependency injection with the Azure .NET SDK](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection). ## Key concepts From 923b9f3c1c16418e72072a44555c1a0ee2993a1e Mon Sep 17 00:00:00 2001 From: Alex Ghiondea Date: Thu, 27 May 2021 17:00:32 -0700 Subject: [PATCH 3/6] Update README.md Change the method named used and show the configuration snippet as well. --- .../Azure.Messaging.ServiceBus/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index 28bf1db99b3ed..d766c127cda53 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -59,17 +59,27 @@ To see how to authenticate using Azure.Identity, view this [example](#authentica ### ASP.NET Core To inject ServiceBusClient as a dependency in an ASP .NET Core app, you can register the client in the `Startup.ConfigureServices` method in `Startup.cs`: -```C# +```csharp public void ConfigureServices(IServiceCollection services) { services.AddAzureClients(builder => { - builder.AddServiceBusClient(Configuration["connection_string_key"]); + builder.AddServiceBusClient(Configuration.GetConnectionString("ServiceBus")); }); services.AddControllers(); } ``` + +To use this you will need to add this to your configuration: +```json +{ + "ConnectionStrings": { + "ServiceBus": "" + } +} +``` + For more details, see [Dependency injection with the Azure .NET SDK](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection). ## Key concepts From 09e4293b626a29932d337485e47827eae1cf8bf0 Mon Sep 17 00:00:00 2001 From: Alex Ghiondea Date: Thu, 27 May 2021 17:01:58 -0700 Subject: [PATCH 4/6] Update sdk/servicebus/Azure.Messaging.ServiceBus/README.md Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com> --- sdk/servicebus/Azure.Messaging.ServiceBus/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index d766c127cda53..65cce3f33bc0a 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -58,7 +58,8 @@ To see how to authenticate using Azure.Identity, view this [example](#authentica ### ASP.NET Core -To inject ServiceBusClient as a dependency in an ASP .NET Core app, you can register the client in the `Startup.ConfigureServices` method in `Startup.cs`: +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) { From e04dd41cfe96e55c3dd4908773a28b34d020848a Mon Sep 17 00:00:00 2001 From: Alex Ghiondea Date: Thu, 27 May 2021 17:02:14 -0700 Subject: [PATCH 5/6] Update sdk/servicebus/Azure.Messaging.ServiceBus/README.md Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com> --- sdk/servicebus/Azure.Messaging.ServiceBus/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index 65cce3f33bc0a..11121901c7178 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -81,7 +81,8 @@ To use this you will need to add this to your configuration: } ``` -For more details, see [Dependency injection with the Azure .NET SDK](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection). + +For more details, see [Dependency injection with the Azure SDK for .NET](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection). ## Key concepts From 40562f70c1d70684929bbd8d49b52c4f4745ae92 Mon Sep 17 00:00:00 2001 From: Scott Addie <10702007+scottaddie@users.noreply.github.com> Date: Fri, 28 May 2021 11:16:02 -0500 Subject: [PATCH 6/6] minor edits --- sdk/servicebus/Azure.Messaging.ServiceBus/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md index 11121901c7178..31767ba20a176 100755 --- a/sdk/servicebus/Azure.Messaging.ServiceBus/README.md +++ b/sdk/servicebus/Azure.Messaging.ServiceBus/README.md @@ -72,7 +72,8 @@ public void ConfigureServices(IServiceCollection services) } ``` -To use this you will need to add this to your configuration: +To use the preceding code, add this to your configuration: + ```json { "ConnectionStrings": { @@ -81,7 +82,6 @@ To use this you will need to add this to your configuration: } ``` - For more details, see [Dependency injection with the Azure SDK for .NET](https://docs.microsoft.com/dotnet/azure/sdk/dependency-injection). ## Key concepts