using Microsoft.Extensions.DependencyInjection; using MQTTnet.Core.Adapter; using MQTTnet.Core.Client; using MQTTnet.Core.ManagedClient; using MQTTnet.Core.Serializer; using MQTTnet.Core.Server; using MQTTnet.Implementations; using System; using Microsoft.Extensions.Logging; using MQTTnet.Core.Diagnostics; namespace MQTTnet { public static class ServiceCollectionExtensions { public static IServiceCollection AddMqttServer(this IServiceCollection services) { services.AddMqttServerServices(); services.AddSingleton(s => s.GetService()); services.AddSingleton(); return services; } public static IServiceCollection AddMqttServerServices(this IServiceCollection services) { services.AddOptions(); services.AddSingleton(); services.AddSingleton(s => s.GetService()); services.AddSingleton(s => s.GetService()); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); return services; } public static IServiceCollection AddMqttServer(this IServiceCollection services, Action configureOptions) { return services .AddMqttServer() .Configure(configureOptions); } public static IServiceCollection AddMqttClient(this IServiceCollection services) { services.AddSingleton(); services.AddSingleton(s => s.GetService()); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); return services; } public static ILoggerFactory AddMqttTrace(this ILoggerFactory factory) { factory.AddProvider(new MqttNetTrace()); return factory; } } }