Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public static class ServiceCollectionExtensions
  2. {
  3. /// <summary>
  4. /// Adds a set of Azure Relays and an associated Request Hanlder.
  5. /// </summary>
  6. /// <typeparam name="T">The type you wish to be injected as the Request Handler for incoming messages</typeparam>
  7. /// <param name="services">Service collection</param>
  8. /// <param name="relayConnectionStrings">Array of relay connection strings</param>
  9. /// <returns>Service Collection</returns>
  10. public static IServiceCollection AddAzureRelayListeners<T> (this IServiceCollection services, params string[] relayConnectionStrings)
  11. where T : class, IRequestHandler
  12.  
  13. {
  14. services.AddSingleton<IRequestHandler, T>();
  15.  
  16. foreach (var relayConnectionString in relayConnectionStrings)
  17. {
  18. services.AddSingleton<IAzureRelayListener>(x => new AzureRelayListener(
  19. x.GetRequiredService<IRequestHandler>(),
  20. relayConnectionString,
  21. x.GetRequiredService<ILogger<AzureRelayListener>>()));
  22. }
  23. return services;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement