using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using MQTTnet.Adapter; using MQTTnet.Diagnostics; using MQTTnet.Server; namespace MQTTnet.AspNetCore { public static class ServiceCollectionExtensions { public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); services.AddSingleton(options); services.AddSingleton(new MqttNetLogger()); services.AddSingleton(); services.AddSingleton(s => s.GetService()); services.AddSingleton(s => s.GetService()); services.AddSingleton(); services.AddSingleton(s => s.GetService()); return services; } } }