Fix ASP.NET Core breaking changes

This commit is contained in:
Christian Kratky
2017-11-23 22:34:16 +01:00
parent e54b4f58df
commit 1bcf7ec29c
3 changed files with 16 additions and 10 deletions
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
@@ -12,12 +13,9 @@ namespace MQTTnet.AspNetCore
{
private readonly MqttServerOptions _options;
public MqttHostedServer(
MqttServerOptions options,
IEnumerable<IMqttServerAdapter> adapters,
IMqttNetLogger logger) : base(adapters, logger)
public MqttHostedServer(MqttServerOptions options, IEnumerable<IMqttServerAdapter> adapters, IMqttNetLogger logger) : base(adapters, logger)
{
_options = options;
_options = options ?? throw new ArgumentNullException(nameof(options));
}
public Task StartAsync(CancellationToken cancellationToken)
@@ -1,17 +1,23 @@
using Microsoft.Extensions.DependencyInjection;
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)
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<MqttHostedServer>();
services.AddSingleton<MqttWebSocketServerAdapter>();
services.AddSingleton<IMqttServerAdapter>(s => s.GetService<MqttWebSocketServerAdapter>());
+3 -1
View File
@@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using MQTTnet.AspNetCore;
using MQTTnet.Core;
using MQTTnet.Core.Server;
namespace MQTTnet.TestApp.AspNetCore2
{
@@ -16,7 +17,8 @@ namespace MQTTnet.TestApp.AspNetCore2
public void ConfigureServices(IServiceCollection services)
{
services.AddHostedMqttServer();
var mqttServerOptions = new MqttServerOptionsBuilder().Build();
services.AddHostedMqttServer(mqttServerOptions);
}
// In class _Startup_ of the ASP.NET Core 2.0 project.