Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MqttClientFactory: Fix CreateLowLevelMqttClient not using method parameters #2110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions Source/MQTTnet/MqttClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@

namespace MQTTnet;

public sealed class MqttClientFactory
public class MqttClientFactory
{
IMqttClientAdapterFactory _clientAdapterFactory;
readonly IMqttNetLogger _logger;
readonly IMqttClientAdapterFactory _clientAdapterFactory;

public MqttClientFactory() : this(new MqttNetNullLogger())
public IMqttNetLogger DefaultLogger => _logger;

public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();

public MqttClientFactory()
: this(new MqttNetNullLogger())
{
}

public MqttClientFactory(IMqttNetLogger logger)
: this(logger, new MqttClientAdapterFactory())
{
DefaultLogger = logger ?? throw new ArgumentNullException(nameof(logger));

_clientAdapterFactory = new MqttClientAdapterFactory();
}

public IMqttNetLogger DefaultLogger { get; }
public MqttClientFactory(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_clientAdapterFactory = clientAdapterFactory ?? throw new ArgumentNullException(nameof(clientAdapterFactory));
}

public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();

public MqttApplicationMessageBuilder CreateApplicationMessageBuilder()
{
Expand All @@ -47,7 +54,7 @@ public MqttClientOptionsBuilder CreateClientOptionsBuilder()

public ILowLevelMqttClient CreateLowLevelMqttClient()
{
return CreateLowLevelMqttClient(DefaultLogger);
return new LowLevelMqttClient(_clientAdapterFactory, _logger);
}

public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger)
Expand All @@ -61,20 +68,20 @@ public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttClientAdapterFactory cl
{
ArgumentNullException.ThrowIfNull(clientAdapterFactory);

return new LowLevelMqttClient(_clientAdapterFactory, DefaultLogger);
return new LowLevelMqttClient(clientAdapterFactory, _logger);
}

public ILowLevelMqttClient CreateLowLevelMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
{
ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(clientAdapterFactory);

return new LowLevelMqttClient(_clientAdapterFactory, logger);
return new LowLevelMqttClient(clientAdapterFactory, logger);
}

public IMqttClient CreateMqttClient()
{
return CreateMqttClient(DefaultLogger);
return new MqttClient(_clientAdapterFactory, _logger);
}

public IMqttClient CreateMqttClient(IMqttNetLogger logger)
Expand All @@ -88,7 +95,7 @@ public IMqttClient CreateMqttClient(IMqttClientAdapterFactory clientAdapterFacto
{
ArgumentNullException.ThrowIfNull(clientAdapterFactory);

return new MqttClient(clientAdapterFactory, DefaultLogger);
return new MqttClient(clientAdapterFactory, _logger);
}

public IMqttClient CreateMqttClient(IMqttNetLogger logger, IMqttClientAdapterFactory clientAdapterFactory)
Expand All @@ -114,9 +121,4 @@ public MqttClientUnsubscribeOptionsBuilder CreateUnsubscribeOptionsBuilder()
return new MqttClientUnsubscribeOptionsBuilder();
}

public MqttClientFactory UseClientAdapterFactory(IMqttClientAdapterFactory clientAdapterFactory)
{
_clientAdapterFactory = clientAdapterFactory ?? throw new ArgumentNullException(nameof(clientAdapterFactory));
return this;
}
}
Loading