mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 19:13:11 +08:00
more extensions for aspnetcore configuration
This commit is contained in:
@@ -13,26 +13,63 @@ namespace MQTTnet.AspNetCore
|
|||||||
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options)
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options)
|
||||||
{
|
{
|
||||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||||
|
|
||||||
|
services.AddSingleton(options);
|
||||||
|
|
||||||
|
services.AddHostedMqttServer();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, Action<MqttServerOptionsBuilder> configure)
|
||||||
|
{
|
||||||
|
var builder = new MqttServerOptionsBuilder();
|
||||||
|
|
||||||
|
configure(builder);
|
||||||
|
|
||||||
|
services.AddSingleton<IMqttServerOptions>(builder.Build());
|
||||||
|
|
||||||
|
services.AddHostedMqttServer();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddHostedMqttServer<TOptions>(this IServiceCollection services)
|
||||||
|
where TOptions : class, IMqttServerOptions
|
||||||
|
{
|
||||||
|
services.AddSingleton<IMqttServerOptions, TOptions>();
|
||||||
|
|
||||||
|
services.AddHostedMqttServer();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services)
|
||||||
|
{
|
||||||
var logger = new MqttNetLogger();
|
var logger = new MqttNetLogger();
|
||||||
var childLogger = logger.CreateChildLogger();
|
var childLogger = logger.CreateChildLogger();
|
||||||
|
|
||||||
services.AddSingleton(options);
|
|
||||||
services.AddSingleton<IMqttNetLogger>(logger);
|
services.AddSingleton<IMqttNetLogger>(logger);
|
||||||
services.AddSingleton(childLogger);
|
services.AddSingleton(childLogger);
|
||||||
services.AddSingleton<MqttHostedServer>();
|
services.AddSingleton<MqttHostedServer>();
|
||||||
services.AddSingleton<IHostedService>(s => s.GetService<MqttHostedServer>());
|
services.AddSingleton<IHostedService>(s => s.GetService<MqttHostedServer>());
|
||||||
services.AddSingleton<IMqttServer>(s => s.GetService<MqttHostedServer>());
|
services.AddSingleton<IMqttServer>(s => s.GetService<MqttHostedServer>());
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddMqttWebSocketServerAdapter(this IServiceCollection services)
|
||||||
|
{
|
||||||
services.AddSingleton<MqttWebSocketServerAdapter>();
|
services.AddSingleton<MqttWebSocketServerAdapter>();
|
||||||
services.AddSingleton<MqttTcpServerAdapter>();
|
|
||||||
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
|
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
|
||||||
|
|
||||||
if (options.DefaultEndpointOptions.IsEnabled)
|
return services;
|
||||||
{
|
}
|
||||||
services.AddSingleton<MqttTcpServerAdapter>();
|
|
||||||
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttTcpServerAdapter>());
|
public static IServiceCollection AddMqttTcpServerAdapter(this IServiceCollection services)
|
||||||
}
|
{
|
||||||
|
services.AddSingleton<MqttTcpServerAdapter>();
|
||||||
|
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttTcpServerAdapter>());
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user