Stardardizing option initialization using lambdas
This commit is contained in:
parent
cb4c05084b
commit
fe41412eeb
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.AspNet.WebSockets.Server;
|
using Microsoft.AspNet.WebSockets.Server;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Builder
|
namespace Microsoft.AspNet.Builder
|
||||||
|
|
@ -9,11 +10,28 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
return builder.UseWebSockets(new WebSocketOptions());
|
if (builder == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(builder));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.UseWebSockets(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder builder, WebSocketOptions options) // TODO: [NotNull]
|
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder builder, Action<WebSocketOptions> configureOptions)
|
||||||
{
|
{
|
||||||
|
if (builder == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(builder));
|
||||||
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = new WebSocketOptions();
|
||||||
|
configureOptions(options);
|
||||||
|
|
||||||
return builder.Use(next => new WebSocketMiddleware(next, options).Invoke);
|
return builder.Use(next => new WebSocketMiddleware(next, options).Invoke);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.WebSockets.Server;
|
|
||||||
|
|
||||||
namespace AutobahnTestServer
|
namespace AutobahnTestServer
|
||||||
{
|
{
|
||||||
|
|
@ -19,9 +18,9 @@ namespace AutobahnTestServer
|
||||||
app.Map("/Managed", managedWebSocketsApp =>
|
app.Map("/Managed", managedWebSocketsApp =>
|
||||||
{
|
{
|
||||||
// Comment this out to test native server implementations
|
// Comment this out to test native server implementations
|
||||||
managedWebSocketsApp.UseWebSockets(new WebSocketOptions()
|
managedWebSocketsApp.UseWebSockets(options =>
|
||||||
{
|
{
|
||||||
ReplaceFeature = true,
|
options.ReplaceFeature = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
managedWebSocketsApp.Use(async (context, next) =>
|
managedWebSocketsApp.Use(async (context, next) =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue