We are using event hubs in our Azure Functions to send messages and this works fine as long as all functions uses the same event hub, then we inject is as follows in startup.cs
.AddSingleton(_ => new EventHubProducerClient(config["EventHubConnectionString"], config["EventHubName"]))
Then we inject this into our functions as follows:
private readonly AuthService _authService;
private readonly ItemService _itemService;
private readonly PromoService _promoService;
private readonly UserService _userService;
private readonly EventHubProducerClient _eventHubClient;
public BarCodeScanV4(AuthService authService, ItemService itemService, PromoService promoService, UserService userService, EventHubProducerClient eventHubClient)
{
_authService = authService ?? throw new ArgumentNullException(nameof(authService));
_itemService = itemService ?? throw new ArgumentNullException(nameof(itemService));
_promoService = promoService ?? throw new ArgumentNullException(nameof(promoService));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_eventHubClient = eventHubClient ?? throw new ArgumentNullException(nameof(eventHubClient));
}
But now I have the need toinject a second eventhub client with a different confoguration, i.e a different eventhubname in the same eventhubnamespace but I cannot figure out how to do this
How can I either
- Change the configuration of my eventhub client on a per function level or
- Inject a second client with the different eventhubname