Question: How to use multiple endpoints?
Hello from Germany!
At first I'd like to thank you for sharing your project!
I'm currently trying to use your MQTT broker with two endpoints ("plain" TCP and Websocket). How can I use both at once without creating multiple instances and syncing them?
Regards Chris
Hello :)
I think, I've found I solution by myself. I have taken a look at your ServiceCollectionExtensions and created a custom one for me. It looks like the following:
public static IServiceCollection E(this IServiceCollection services, IMqttServerOptions 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<MqttServerAdapter>();
services.AddSingleton<IEnumerable<IMqttServerAdapter>>(s =>
{
List<IMqttServerAdapter> adapters = new List<IMqttServerAdapter>();
adapters.Add(s.GetService<MqttServerAdapter>());
adapters.Add(s.GetService<MqttWebSocketServerAdapter>());
return adapters;
});
return services;
}
Please let me know, if there is a nicer way, as I'm not into the dependency injection framework of .net Core. :)
Regards Chris
Hi @chris1705, at the moment there is no other way as the one you found by yourself. So it is the best one 😄
Best regards Christian