瀏覽代碼

Merge pull request #402 from JanEggers/AspNetMqttServerOptionsBuilder

added AspNetMqttServerOptionsBuilder
release/3.x.x
Christian 6 年之前
committed by GitHub
父節點
當前提交
dd83a360b4
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 2 個檔案被更改,包括 33 行新增5 行删除
  1. +15
    -0
      Source/MQTTnet.AspnetCore/AspNetMqttServerOptionsBuilder.cs
  2. +18
    -5
      Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs

+ 15
- 0
Source/MQTTnet.AspnetCore/AspNetMqttServerOptionsBuilder.cs 查看文件

@@ -0,0 +1,15 @@
using MQTTnet.Server;
using System;

namespace MQTTnet.AspNetCore
{
public class AspNetMqttServerOptionsBuilder : MqttServerOptionsBuilder
{
public AspNetMqttServerOptionsBuilder(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}

public IServiceProvider ServiceProvider { get; }
}
}

+ 18
- 5
Source/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs 查看文件

@@ -20,14 +20,27 @@ namespace MQTTnet.AspNetCore

return services;
}
public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, Action<MqttServerOptionsBuilder> configure)
{
var builder = new MqttServerOptionsBuilder();
services.AddSingleton<IMqttServerOptions>(s => {
var builder = new MqttServerOptionsBuilder();
configure(builder);
return builder.Build();
});

configure(builder);
services.AddSingleton<IMqttServerOptions>(builder.Build());
services.AddHostedMqttServer();

return services;
}

public static IServiceCollection AddHostedMqttServerWithServices(this IServiceCollection services, Action<AspNetMqttServerOptionsBuilder> configure)
{
services.AddSingleton<IMqttServerOptions>(s => {
var builder = new AspNetMqttServerOptionsBuilder(s);
configure(builder);
return builder.Build();
});

services.AddHostedMqttServer();



Loading…
取消
儲存