Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class ServiceCollectionExtensions
- {
- /// <summary>
- /// Adds a set of Azure Relays and an associated Request Hanlder.
- /// </summary>
- /// <typeparam name="T">The type you wish to be injected as the Request Handler for incoming messages</typeparam>
- /// <param name="services">Service collection</param>
- /// <param name="relayConnectionStrings">Array of relay connection strings</param>
- /// <returns>Service Collection</returns>
- public static IServiceCollection AddAzureRelayListeners<T> (this IServiceCollection services, params string[] relayConnectionStrings)
- where T : class, IRequestHandler
- {
- services.AddSingleton<IRequestHandler, T>();
- foreach (var relayConnectionString in relayConnectionStrings)
- {
- services.AddSingleton<IAzureRelayListener>(x => new AzureRelayListener(
- x.GetRequiredService<IRequestHandler>(),
- relayConnectionString,
- x.GetRequiredService<ILogger<AzureRelayListener>>()));
- }
- return services;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement