Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

32 linhas
1.2 KiB

  1. using System;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Hosting;
  4. using MQTTnet.Adapter;
  5. using MQTTnet.Diagnostics;
  6. using MQTTnet.Server;
  7. using MQTTnet.Implementations;
  8. namespace MQTTnet.AspNetCore
  9. {
  10. public static class ServiceCollectionExtensions
  11. {
  12. public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options)
  13. {
  14. if (options == null) throw new ArgumentNullException(nameof(options));
  15. services.AddSingleton(options);
  16. services.AddSingleton<IMqttNetLogger>(new MqttNetLogger());
  17. services.AddSingleton<MqttHostedServer>();
  18. services.AddSingleton<IHostedService>(s => s.GetService<MqttHostedServer>());
  19. services.AddSingleton<IMqttServer>(s => s.GetService<MqttHostedServer>());
  20. services.AddSingleton<MqttWebSocketServerAdapter>();
  21. services.AddSingleton<MqttTcpServerAdapter>();
  22. services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
  23. services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttTcpServerAdapter>());
  24. return services;
  25. }
  26. }
  27. }