Updating to new options pattern
This commit is contained in:
parent
07785c9ae0
commit
cd813844a0
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNet.Builder;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.WebSockets.Protocol;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNet.WebSockets.Server
|
||||
{
|
||||
|
|
@ -18,10 +19,19 @@ namespace Microsoft.AspNet.WebSockets.Server
|
|||
private readonly RequestDelegate _next;
|
||||
private readonly WebSocketOptions _options;
|
||||
|
||||
public WebSocketMiddleware(RequestDelegate next, WebSocketOptions options)
|
||||
public WebSocketMiddleware(RequestDelegate next, IOptions<WebSocketOptions> options)
|
||||
{
|
||||
if (next == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(next));
|
||||
}
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
_next = next;
|
||||
_options = options;
|
||||
_options = options.Value;
|
||||
|
||||
// TODO: validate options.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.WebSockets.Server;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
|
|
@ -15,24 +16,7 @@ namespace Microsoft.AspNet.Builder
|
|||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
return app.UseWebSockets(options => { });
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder app, Action<WebSocketOptions> configureOptions)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
if (configureOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configureOptions));
|
||||
}
|
||||
|
||||
var options = new WebSocketOptions();
|
||||
configureOptions(options);
|
||||
|
||||
return app.UseMiddleware<WebSocketMiddleware>(options);
|
||||
return app.UseMiddleware<WebSocketMiddleware>();
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseWebSockets(this IApplicationBuilder app, WebSocketOptions options)
|
||||
|
|
@ -46,7 +30,7 @@ namespace Microsoft.AspNet.Builder
|
|||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
return app.UseMiddleware<WebSocketMiddleware>(options);
|
||||
return app.UseMiddleware<WebSocketMiddleware>(Options.Create(options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.WebSockets.Server
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for the WebSocketMiddleware
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||
"Microsoft.AspNet.WebSockets.Protocol": "1.0.0-*"
|
||||
"Microsoft.AspNet.WebSockets.Protocol": "1.0.0-*",
|
||||
"Microsoft.Extensions.Options": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace AutobahnTestServer
|
||||
{
|
||||
|
|
@ -18,9 +17,9 @@ namespace AutobahnTestServer
|
|||
app.Map("/Managed", managedWebSocketsApp =>
|
||||
{
|
||||
// Comment this out to test native server implementations
|
||||
managedWebSocketsApp.UseWebSockets(options =>
|
||||
managedWebSocketsApp.UseWebSockets(new WebSocketOptions
|
||||
{
|
||||
options.ReplaceFeature = true;
|
||||
ReplaceFeature = true
|
||||
});
|
||||
|
||||
managedWebSocketsApp.Use(async (context, next) =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue