From c43acf7dacf4a5ddd133bb242cdb8f5d36cfd3a6 Mon Sep 17 00:00:00 2001 From: JanEggers Date: Fri, 29 Jun 2018 20:05:48 +0200 Subject: [PATCH] more extensions for aspnetcore configuration --- .../ServiceCollectionExtensions.cs | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs b/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs index fa061eb..8b65bbe 100644 --- a/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs +++ b/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs @@ -13,26 +13,63 @@ namespace MQTTnet.AspNetCore public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); + + services.AddSingleton(options); + + services.AddHostedMqttServer(); + + return services; + } + + public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, Action configure) + { + var builder = new MqttServerOptionsBuilder(); + + configure(builder); + + services.AddSingleton(builder.Build()); + + services.AddHostedMqttServer(); + + return services; + } + + public static IServiceCollection AddHostedMqttServer(this IServiceCollection services) + where TOptions : class, IMqttServerOptions + { + services.AddSingleton(); + + services.AddHostedMqttServer(); + return services; + } + + public static IServiceCollection AddHostedMqttServer(this IServiceCollection services) + { var logger = new MqttNetLogger(); var childLogger = logger.CreateChildLogger(); - services.AddSingleton(options); services.AddSingleton(logger); services.AddSingleton(childLogger); services.AddSingleton(); services.AddSingleton(s => s.GetService()); services.AddSingleton(s => s.GetService()); + + return services; + } + public static IServiceCollection AddMqttWebSocketServerAdapter(this IServiceCollection services) + { services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(s => s.GetService()); - if (options.DefaultEndpointOptions.IsEnabled) - { - services.AddSingleton(); - services.AddSingleton(s => s.GetService()); - } + return services; + } + + public static IServiceCollection AddMqttTcpServerAdapter(this IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(s => s.GetService()); return services; }