You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

25 lines
846 B

  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.Hosting;
  3. using MQTTnet.Core.Adapter;
  4. using MQTTnet.Core.Server;
  5. namespace MQTTnet.AspNetCore
  6. {
  7. public static class ServiceCollectionExtensions
  8. {
  9. public static IServiceCollection AddHostedMqttServer(this IServiceCollection services)
  10. {
  11. services.AddMqttServerServices();
  12. services.AddSingleton<IHostedService>(s => s.GetService<MqttHostedServer>());
  13. services.AddSingleton<IMqttServer>(s => s.GetService<MqttHostedServer>());
  14. services.AddSingleton<MqttHostedServer>();
  15. services.AddSingleton<MqttWebSocketServerAdapter>();
  16. services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
  17. return services;
  18. }
  19. }
  20. }