|
|
@@ -7,8 +7,9 @@ using MQTTnet.Client; |
|
|
|
using MQTTnet.Client.Connecting; |
|
|
|
using MQTTnet.Client.Disconnecting; |
|
|
|
using MQTTnet.Client.Options; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Text.Json.Serialization; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace BPA.MQTTnet.Extensions.Extensions |
|
|
@@ -18,12 +19,9 @@ namespace BPA.MQTTnet.Extensions.Extensions |
|
|
|
|
|
|
|
public static IServiceCollection AddMqttClientHostedService(this IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
|
ClientSettings clientSettings = new ClientSettings(); |
|
|
|
configuration.GetSection(nameof(ClientSettings)).Bind(clientSettings); |
|
|
|
var clientSettings = JsonConvert.DeserializeObject<ClientSettings>(configuration.GetSection(nameof(ClientSettings)).Value); |
|
|
|
services.AddSingleton(clientSettings); |
|
|
|
|
|
|
|
BrokerHostSettings brokerHostSettings = new BrokerHostSettings(); |
|
|
|
configuration.GetSection(nameof(BrokerHostSettings)).Bind(brokerHostSettings); |
|
|
|
var brokerHostSettings = JsonConvert.DeserializeObject<BrokerHostSettings>(configuration.GetSection(nameof(BrokerHostSettings)).Value); |
|
|
|
services.AddSingleton(brokerHostSettings); |
|
|
|
services.AddMqttClientServiceWithConfig(); |
|
|
|
//services.AddMqttClientServiceWithConfig(aspOptionBuilder => |
|
|
|