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.
 
 
 
 

26 lines
872 B

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