mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using MQTTnet.Core.Adapter;
|
|
using MQTTnet.Core.Diagnostics;
|
|
using MQTTnet.Core.Server;
|
|
|
|
namespace MQTTnet.AspNetCore
|
|
{
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, MqttServerOptions options)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
|
|
services.AddSingleton(options);
|
|
services.AddSingleton<IMqttNetLogger>(new MqttNetLogger());
|
|
services.AddSingleton<MqttHostedServer>();
|
|
services.AddSingleton<IHostedService>(s => s.GetService<MqttHostedServer>());
|
|
services.AddSingleton<IMqttServer>(s => s.GetService<MqttHostedServer>());
|
|
|
|
services.AddSingleton<MqttWebSocketServerAdapter>();
|
|
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|