diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index 61707d850..e04b0b0d2 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -1,2 +1,3 @@ * [Server] Added new events for delivered and dropped messages (#1866, thanks to @kallayj). * [Server] The server will no longer treat a client which is receiving a large payload as alive. The packet must be received completely within the keep alive boundaries (BREAKING CHANGE!, #1883). +* [Server] Fixed "service not registered" exception in ASP.NET integration (#1889). diff --git a/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs b/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs index 9b46ad19f..1186baeb7 100644 --- a/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs +++ b/Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs @@ -5,6 +5,7 @@ using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; using MQTTnet.Adapter; using MQTTnet.Diagnostics; using MQTTnet.Implementations; @@ -58,7 +59,8 @@ public static void AddHostedMqttServer(this IServiceCollection services) services.TryAddSingleton(new MqttFactory()); services.AddSingleton(); - services.AddHostedService(); + services.AddSingleton(s => s.GetService()); + services.AddSingleton(s => s.GetService()); } public static IServiceCollection AddHostedMqttServerWithServices(this IServiceCollection services, Action configure) diff --git a/Source/MQTTnet/Adapter/IMqttServerAdapter.cs b/Source/MQTTnet/Adapter/IMqttServerAdapter.cs index 328430521..47f3c1d37 100644 --- a/Source/MQTTnet/Adapter/IMqttServerAdapter.cs +++ b/Source/MQTTnet/Adapter/IMqttServerAdapter.cs @@ -14,6 +14,7 @@ public interface IMqttServerAdapter : IDisposable Func ClientHandler { get; set; } Task StartAsync(MqttServerOptions options, IMqttNetLogger logger); + Task StopAsync(); } }