No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

64 líneas
2.2 KiB

  1. using Microsoft.Extensions.DependencyInjection;
  2. using MQTTnet.Core.Adapter;
  3. using MQTTnet.Core.Client;
  4. using MQTTnet.Core.ManagedClient;
  5. using MQTTnet.Core.Serializer;
  6. using MQTTnet.Core.Server;
  7. using MQTTnet.Implementations;
  8. using System;
  9. using Microsoft.Extensions.Logging;
  10. using MQTTnet.Core.Diagnostics;
  11. namespace MQTTnet
  12. {
  13. public static class ServiceCollectionExtensions
  14. {
  15. public static IServiceCollection AddMqttServer(this IServiceCollection services)
  16. {
  17. services.AddOptions();
  18. services.AddSingleton<MqttFactory>();
  19. services.AddSingleton<IMqttCommunicationAdapterFactory, MqttFactory>();
  20. services.AddSingleton<IMqttClientSesssionFactory, MqttFactory>();
  21. services.AddSingleton<IMqttServer,MqttServer>();
  22. services.AddSingleton<MqttServer>();
  23. services.AddTransient<IMqttServerAdapter, MqttServerAdapter>();
  24. services.AddTransient<IMqttPacketSerializer, MqttPacketSerializer>();
  25. services.AddTransient<MqttClientSessionsManager>();
  26. services.AddTransient<MqttClientRetainedMessagesManager>();
  27. return services;
  28. }
  29. public static IServiceCollection AddMqttServer(this IServiceCollection services, Action<MqttServerOptions> configureOptions)
  30. {
  31. return services
  32. .AddMqttServer()
  33. .Configure(configureOptions);
  34. }
  35. public static IServiceCollection AddMqttClient(this IServiceCollection services)
  36. {
  37. services.AddSingleton<MqttFactory>();
  38. services.AddSingleton<IMqttCommunicationAdapterFactory, MqttFactory>();
  39. services.AddTransient<IMqttClient, MqttClient>();
  40. services.AddTransient<MqttClient>();
  41. services.AddTransient<IManagedMqttClient, ManagedMqttClient>();
  42. services.AddTransient<ManagedMqttClient>();
  43. services.AddTransient<IMqttPacketSerializer, MqttPacketSerializer>();
  44. services.AddTransient<MqttPacketDispatcher>();
  45. return services;
  46. }
  47. public static ILoggerFactory AddMqttTrace(this ILoggerFactory factory)
  48. {
  49. factory.AddProvider(new MqttNetTrace());
  50. return factory;
  51. }
  52. }
  53. }