Change IEndpointConventionBuilder extension methods to use generic argument (#8906)
This commit is contained in:
parent
3c22e34d50
commit
da66edc8ff
|
|
@ -14,6 +14,7 @@
|
|||
https://dotnetfeed.blob.core.windows.net/aspnet-entityframeworkcore/index.json;
|
||||
https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore-tooling/index.json;
|
||||
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
|
||||
https://grpc.jfrog.io/grpc/api/nuget/v3/grpc-nuget-dev;
|
||||
https://api.nuget.org/v3/index.json;
|
||||
</RestoreSources>
|
||||
<!-- TODO remove this once we remove usages of Internal.AspNetCore.Sdk. -->
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@
|
|||
<CastleCorePackageVersion>4.2.1</CastleCorePackageVersion>
|
||||
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
|
||||
<GoogleProtobufPackageVersion>3.7.0</GoogleProtobufPackageVersion>
|
||||
<GrpcAspNetCoreServerPackageVersion>0.1.20-pre1</GrpcAspNetCoreServerPackageVersion>
|
||||
<GrpcAspNetCoreServerPackageVersion>0.1.21-dev201905010701</GrpcAspNetCoreServerPackageVersion>
|
||||
<GrpcToolsPackageVersion>1.20.0-pre3</GrpcToolsPackageVersion>
|
||||
<IdentityServer4AspNetIdentityPackageVersion>3.0.0-preview3.4</IdentityServer4AspNetIdentityPackageVersion>
|
||||
<IdentityServer4EntityFrameworkPackageVersion>3.0.0-preview3.4</IdentityServer4EntityFrameworkPackageVersion>
|
||||
|
|
|
|||
|
|
@ -5,15 +5,14 @@ namespace Microsoft.AspNetCore.Builder
|
|||
{
|
||||
public static partial class ComponentEndpointConventionBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder AddComponent(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, System.Type componentType, string selector) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder AddComponent<TComponent>(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, string selector) { throw null; }
|
||||
public static TBuilder AddComponent<TBuilder>(this TBuilder builder, System.Type componentType, string selector) where TBuilder : Microsoft.AspNetCore.SignalR.IHubEndpointConventionBuilder { throw null; }
|
||||
}
|
||||
public static partial class ComponentEndpointRouteBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Type componentType, string selector, string path) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapBlazorHub<TComponent>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string selector) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapBlazorHub<TComponent>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string selector, string path) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
|
||||
public static Microsoft.AspNetCore.Components.Server.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) { throw null; }
|
||||
public static Microsoft.AspNetCore.Components.Server.ComponentEndpointConventionBuilder MapBlazorHub(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, System.Type componentType, string selector, string path) { throw null; }
|
||||
public static Microsoft.AspNetCore.Components.Server.ComponentEndpointConventionBuilder MapBlazorHub<TComponent>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string selector) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
|
||||
public static Microsoft.AspNetCore.Components.Server.ComponentEndpointConventionBuilder MapBlazorHub<TComponent>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string selector, string path) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
|
||||
}
|
||||
}
|
||||
namespace Microsoft.AspNetCore.Components.Browser.Rendering
|
||||
|
|
@ -31,6 +30,11 @@ namespace Microsoft.AspNetCore.Components.Server
|
|||
public System.TimeSpan DisconnectedCircuitRetentionPeriod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||
public int MaxRetainedDisconnectedCircuits { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||
}
|
||||
public sealed partial class ComponentEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.SignalR.IHubEndpointConventionBuilder
|
||||
{
|
||||
internal ComponentEndpointConventionBuilder() { }
|
||||
public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
|
||||
}
|
||||
public sealed partial class ComponentHub : Microsoft.AspNetCore.SignalR.Hub
|
||||
{
|
||||
public ComponentHub(System.IServiceProvider services, Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Server.ComponentHub> logger) { }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds conventions that will be used for customization of ComponentHub <see cref="EndpointBuilder"/> instances.
|
||||
/// </summary>
|
||||
public sealed class ComponentEndpointConventionBuilder : IHubEndpointConventionBuilder
|
||||
{
|
||||
private readonly IEndpointConventionBuilder _endpointConventionBuilder;
|
||||
|
||||
internal ComponentEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder)
|
||||
{
|
||||
_endpointConventionBuilder = endpointConventionBuilder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified convention to the builder. Conventions are used to customize <see cref="EndpointBuilder"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="convention">The convention to add to the builder.</param>
|
||||
public void Add(Action<EndpointBuilder> convention)
|
||||
{
|
||||
_endpointConventionBuilder.Add(convention);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,45 +4,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions for <see cref="IEndpointConventionBuilder"/>.
|
||||
/// Extensions for <see cref="HubEndpointConventionBuilder"/>.
|
||||
/// </summary>
|
||||
public static class ComponentEndpointConventionBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <typeparamref name="TComponent"/> to the list of components registered with this <see cref="ComponentHub"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TComponent">The component type.</typeparam>
|
||||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="selector">A CSS selector that identifies the DOM element into which the <typeparamref name="TComponent"/> will be placed.</param>
|
||||
/// <returns>The <paramref name="builder"/>.</returns>
|
||||
public static IEndpointConventionBuilder AddComponent<TComponent>(this IEndpointConventionBuilder builder, string selector)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (selector == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(selector));
|
||||
}
|
||||
|
||||
return AddComponent(builder, typeof(TComponent), selector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds <paramref name="componentType"/> to the list of components registered with this <see cref="ComponentHub"/> instance.
|
||||
/// The selector will default to the component name in lowercase.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="builder">The <see cref="IHubEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="componentType">The component type.</param>
|
||||
/// <param name="selector">The component selector in the DOM for the <paramref name="componentType"/>.</param>
|
||||
/// <returns>The <paramref name="builder"/>.</returns>
|
||||
public static IEndpointConventionBuilder AddComponent(this IEndpointConventionBuilder builder, Type componentType, string selector)
|
||||
public static TBuilder AddComponent<TBuilder>(this TBuilder builder, Type componentType, string selector) where TBuilder : IHubEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
|
|
@ -17,15 +18,15 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// Maps the SignalR <see cref="ComponentHub"/> to the path <see cref="ComponentHub.DefaultPath"/>.
|
||||
/// </summary>
|
||||
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder MapBlazorHub(this IEndpointRouteBuilder endpoints)
|
||||
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
|
||||
public static ComponentEndpointConventionBuilder MapBlazorHub(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
if (endpoints == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(endpoints));
|
||||
}
|
||||
|
||||
return endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath);
|
||||
return new ComponentEndpointConventionBuilder(endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -35,8 +36,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <typeparam name="TComponent">The first <see cref="IComponent"/> associated with this <see cref="ComponentHub"/>.</typeparam>
|
||||
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param>
|
||||
/// <param name="selector">The selector for the <typeparamref name="TComponent"/>.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder MapBlazorHub<TComponent>(
|
||||
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
|
||||
public static ComponentEndpointConventionBuilder MapBlazorHub<TComponent>(
|
||||
this IEndpointRouteBuilder endpoints,
|
||||
string selector) where TComponent: IComponent
|
||||
{
|
||||
|
|
@ -61,8 +62,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/>.</param>
|
||||
/// <param name="selector">The selector for the <typeparamref name="TComponent"/>.</param>
|
||||
/// <param name="path">The path to map to which the <see cref="ComponentHub"/> will be mapped.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder MapBlazorHub<TComponent>(
|
||||
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
|
||||
public static ComponentEndpointConventionBuilder MapBlazorHub<TComponent>(
|
||||
this IEndpointRouteBuilder endpoints,
|
||||
string selector,
|
||||
string path) where TComponent : IComponent
|
||||
|
|
@ -93,8 +94,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="componentType">The first <see cref="IComponent"/> associated with this <see cref="ComponentHub"/>.</param>
|
||||
/// <param name="selector">The selector for the <paramref name="componentType"/>.</param>
|
||||
/// <param name="path">The path to map to which the <see cref="ComponentHub"/> will be mapped.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder MapBlazorHub(
|
||||
/// <returns>The <see cref="ComponentEndpointConventionBuilder"/>.</returns>
|
||||
public static ComponentEndpointConventionBuilder MapBlazorHub(
|
||||
this IEndpointRouteBuilder endpoints,
|
||||
Type componentType,
|
||||
string selector,
|
||||
|
|
@ -120,7 +121,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
throw new ArgumentNullException(nameof(selector));
|
||||
}
|
||||
|
||||
return endpoints.MapHub<ComponentHub>(path).AddComponent(componentType, selector);
|
||||
return new ComponentEndpointConventionBuilder(endpoints.MapHub<ComponentHub>(path)).AddComponent(componentType, selector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace TestServer
|
|||
|
||||
subdirApp.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath).AddComponent<Index>(selector: "root");
|
||||
endpoints.MapHub<ComponentHub>(ComponentHub.DefaultPath).AddComponent(typeof(Index), selector: "root");
|
||||
});
|
||||
|
||||
subdirApp.MapWhen(
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
public static partial class RoutingEndpointConventionBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder RequireHost(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, params string[] hosts) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder WithDisplayName(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, System.Func<Microsoft.AspNetCore.Builder.EndpointBuilder, string> func) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder WithDisplayName(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, string displayName) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder WithMetadata(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, params object[] items) { throw null; }
|
||||
public static TBuilder RequireHost<TBuilder>(this TBuilder builder, params string[] hosts) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder WithDisplayName<TBuilder>(this TBuilder builder, System.Func<Microsoft.AspNetCore.Builder.EndpointBuilder, string> func) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder WithDisplayName<TBuilder>(this TBuilder builder, string displayName) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder WithMetadata<TBuilder>(this TBuilder builder, params object[] items) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
}
|
||||
}
|
||||
namespace Microsoft.AspNetCore.Routing
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// An empty collection means any host will be accepted.
|
||||
/// </param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static IEndpointConventionBuilder RequireHost(this IEndpointConventionBuilder builder, params string[] hosts)
|
||||
public static TBuilder RequireHost<TBuilder>(this TBuilder builder, params string[] hosts) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="displayName">The display name.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder WithDisplayName(this IEndpointConventionBuilder builder, string displayName)
|
||||
public static TBuilder WithDisplayName<TBuilder>(this TBuilder builder, string displayName) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="func">A delegate that produces the display name for each <see cref="EndpointBuilder"/>.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder WithDisplayName(this IEndpointConventionBuilder builder, Func<EndpointBuilder, string> func)
|
||||
public static TBuilder WithDisplayName<TBuilder>(this TBuilder builder, Func<EndpointBuilder, string> func) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
|
||||
/// <param name="items">A collection of metadata items.</param>
|
||||
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
|
||||
public static IEndpointConventionBuilder WithMetadata(this IEndpointConventionBuilder builder, params object[] items)
|
||||
public static TBuilder WithMetadata<TBuilder>(this TBuilder builder, params object[] items) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Routing.Patterns;
|
||||
using Xunit;
|
||||
|
|
@ -26,6 +28,19 @@ namespace Microsoft.AspNetCore.Builder
|
|||
Assert.Equal(new[] { "www.example.com", "example.com" }, metadata.Hosts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequireHost_ChainedCall_ReturnedBuilderIsDerivedType()
|
||||
{
|
||||
// Arrange
|
||||
var builder = CreateBuilder();
|
||||
|
||||
// Act
|
||||
var chainedBuilder = builder.RequireHost("test");
|
||||
|
||||
// Assert
|
||||
Assert.True(chainedBuilder.TestProperty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithDisplayName_String_SetsDisplayName()
|
||||
{
|
||||
|
|
@ -40,6 +55,19 @@ namespace Microsoft.AspNetCore.Builder
|
|||
Assert.Equal("test", endpoint.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithDisplayName_ChainedCall_ReturnedBuilderIsDerivedType()
|
||||
{
|
||||
// Arrange
|
||||
var builder = CreateBuilder();
|
||||
|
||||
// Act
|
||||
var chainedBuilder = builder.WithDisplayName("test");
|
||||
|
||||
// Assert
|
||||
Assert.True(chainedBuilder.TestProperty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithDisplayName_Func_SetsDisplayName()
|
||||
{
|
||||
|
|
@ -74,12 +102,48 @@ namespace Microsoft.AspNetCore.Builder
|
|||
Assert.Equal("test", @string);
|
||||
}
|
||||
|
||||
private DefaultEndpointConventionBuilder CreateBuilder()
|
||||
[Fact]
|
||||
public void WithMetadata_ChainedCall_ReturnedBuilderIsDerivedType()
|
||||
{
|
||||
return new DefaultEndpointConventionBuilder(new RouteEndpointBuilder(
|
||||
// Arrange
|
||||
var builder = CreateBuilder();
|
||||
|
||||
// Act
|
||||
var chainedBuilder = builder.WithMetadata("test");
|
||||
|
||||
// Assert
|
||||
Assert.True(chainedBuilder.TestProperty);
|
||||
}
|
||||
|
||||
private TestEndpointConventionBuilder CreateBuilder()
|
||||
{
|
||||
var conventionBuilder = new DefaultEndpointConventionBuilder(new RouteEndpointBuilder(
|
||||
TestConstants.EmptyRequestDelegate,
|
||||
RoutePatternFactory.Parse("/test"),
|
||||
order: 0));
|
||||
|
||||
return new TestEndpointConventionBuilder(conventionBuilder);
|
||||
}
|
||||
|
||||
private class TestEndpointConventionBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
private DefaultEndpointConventionBuilder _endpointConventionBuilder;
|
||||
public bool TestProperty { get; } = true;
|
||||
|
||||
public TestEndpointConventionBuilder(DefaultEndpointConventionBuilder endpointConventionBuilder)
|
||||
{
|
||||
_endpointConventionBuilder = endpointConventionBuilder;
|
||||
}
|
||||
|
||||
public void Add(Action<EndpointBuilder> convention)
|
||||
{
|
||||
_endpointConventionBuilder.Add(convention);
|
||||
}
|
||||
|
||||
public Endpoint Build()
|
||||
{
|
||||
return _endpointConventionBuilder.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
{
|
||||
public static partial class CorsEndpointConventionBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder WithCorsPolicy(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, System.Action<Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder> configurePolicy) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder WithCorsPolicy(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, string policyName) { throw null; }
|
||||
public static TBuilder WithCorsPolicy<TBuilder>(this TBuilder builder, System.Action<Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder> configurePolicy) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder WithCorsPolicy<TBuilder>(this TBuilder builder, string policyName) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
}
|
||||
public static partial class CorsMiddlewareExtensions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The endpoint convention builder.</param>
|
||||
/// <param name="policyName">The CORS policy name.</param>
|
||||
/// <returns>The original convention builder parameter.</returns>
|
||||
public static IEndpointConventionBuilder WithCorsPolicy(this IEndpointConventionBuilder builder, string policyName)
|
||||
public static TBuilder WithCorsPolicy<TBuilder>(this TBuilder builder, string policyName) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The endpoint convention builder.</param>
|
||||
/// <param name="configurePolicy">A delegate which can use a policy builder to build a policy.</param>
|
||||
/// <returns>The original convention builder parameter.</returns>
|
||||
public static IEndpointConventionBuilder WithCorsPolicy(this IEndpointConventionBuilder builder, Action<CorsPolicyBuilder> configurePolicy)
|
||||
public static TBuilder WithCorsPolicy<TBuilder>(this TBuilder builder, Action<CorsPolicyBuilder> configurePolicy) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,19 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
|||
Assert.True(metadata.Policy.AllowAnyOrigin);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithCorsPolicy_ChainedCall_ReturnedBuilderIsDerivedType()
|
||||
{
|
||||
// Arrange
|
||||
var testConventionBuilder = new TestEndpointConventionBuilder();
|
||||
|
||||
// Act
|
||||
var builder = testConventionBuilder.WithCorsPolicy("TestPolicyName");
|
||||
|
||||
// Assert
|
||||
Assert.True(builder.TestProperty);
|
||||
}
|
||||
|
||||
private class TestEndpointBuilder : EndpointBuilder
|
||||
{
|
||||
public override Endpoint Build()
|
||||
|
|
@ -66,6 +79,7 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
|||
private class TestEndpointConventionBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
public IList<Action<EndpointBuilder>> Conventions { get; } = new List<Action<EndpointBuilder>>();
|
||||
public bool TestProperty { get; } = true;
|
||||
|
||||
public void Add(Action<EndpointBuilder> convention)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -250,9 +250,9 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
public static partial class AuthorizationEndpointConventionBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder RequireAuthorization(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder RequireAuthorization(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, params Microsoft.AspNetCore.Authorization.IAuthorizeData[] authorizeData) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder RequireAuthorization(this Microsoft.AspNetCore.Builder.IEndpointConventionBuilder builder, params string[] policyNames) { throw null; }
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder, params Microsoft.AspNetCore.Authorization.IAuthorizeData[] authorizeData) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder, params string[] policyNames) where TBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { throw null; }
|
||||
}
|
||||
}
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The endpoint convention builder.</param>
|
||||
/// <param name="authorizeData">A collection of <see cref="IAuthorizeData"/>.</param>
|
||||
/// <returns>The original convention builder parameter.</returns>
|
||||
public static IEndpointConventionBuilder RequireAuthorization(this IEndpointConventionBuilder builder, params IAuthorizeData[] authorizeData)
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder, params IAuthorizeData[] authorizeData) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="builder">The endpoint convention builder.</param>
|
||||
/// <param name="policyNames">A collection of policy names.</param>
|
||||
/// <returns>The original convention builder parameter.</returns>
|
||||
public static IEndpointConventionBuilder RequireAuthorization(this IEndpointConventionBuilder builder, params string[] policyNames)
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder, params string[] policyNames) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// </summary>
|
||||
/// <param name="builder">The endpoint convention builder.</param>
|
||||
/// <returns>The original convention builder parameter.</returns>
|
||||
public static IEndpointConventionBuilder RequireAuthorization(this IEndpointConventionBuilder builder)
|
||||
public static TBuilder RequireAuthorization<TBuilder>(this TBuilder builder) where TBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -70,9 +70,23 @@ namespace Microsoft.AspNetCore.Authorization.Test
|
|||
Assert.Null(authMetadata.Policy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequireAuthorization_ChainedCall()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new TestEndpointConventionBuilder();
|
||||
|
||||
// Act
|
||||
var chainedBuilder = builder.RequireAuthorization();
|
||||
|
||||
// Assert
|
||||
Assert.True(chainedBuilder.TestProperty);
|
||||
}
|
||||
|
||||
private class TestEndpointConventionBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
public IList<Action<EndpointBuilder>> Conventions { get; } = new List<Action<EndpointBuilder>>();
|
||||
public bool TestProperty { get; } = true;
|
||||
|
||||
public void Add(Action<EndpointBuilder> convention)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
{
|
||||
public static partial class HubEndpointRouteBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
|
||||
public static Microsoft.AspNetCore.SignalR.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
|
||||
public static Microsoft.AspNetCore.SignalR.HubEndpointConventionBuilder MapHub<THub>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { throw null; }
|
||||
}
|
||||
public static partial class SignalRAppBuilderExtensions
|
||||
{
|
||||
|
|
@ -20,12 +20,20 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubCallerContext connection) { throw null; }
|
||||
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubConnectionContext connection) { throw null; }
|
||||
}
|
||||
public sealed partial class HubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder, Microsoft.AspNetCore.SignalR.IHubEndpointConventionBuilder
|
||||
{
|
||||
internal HubEndpointConventionBuilder() { }
|
||||
public void Add(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> convention) { }
|
||||
}
|
||||
public partial class HubRouteBuilder
|
||||
{
|
||||
public HubRouteBuilder(Microsoft.AspNetCore.Http.Connections.ConnectionsRouteBuilder routes) { }
|
||||
public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path) where THub : Microsoft.AspNetCore.SignalR.Hub { }
|
||||
public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { }
|
||||
}
|
||||
public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
|
||||
{
|
||||
}
|
||||
}
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds conventions that will be used for customization of Hub <see cref="EndpointBuilder"/> instances.
|
||||
/// </summary>
|
||||
public sealed class HubEndpointConventionBuilder : IHubEndpointConventionBuilder
|
||||
{
|
||||
private readonly IEndpointConventionBuilder _endpointConventionBuilder;
|
||||
|
||||
internal HubEndpointConventionBuilder(IEndpointConventionBuilder endpointConventionBuilder)
|
||||
{
|
||||
_endpointConventionBuilder = endpointConventionBuilder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified convention to the builder. Conventions are used to customize <see cref="EndpointBuilder"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="convention">The convention to add to the builder.</param>
|
||||
public void Add(Action<EndpointBuilder> convention)
|
||||
{
|
||||
_endpointConventionBuilder.Add(convention);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,8 +19,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <typeparam name="THub">The <see cref="Hub"/> type to map requests to.</typeparam>
|
||||
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
|
||||
/// <param name="pattern">The route pattern.</param>
|
||||
/// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
|
||||
public static IEndpointConventionBuilder MapHub<THub>(this IEndpointRouteBuilder endpoints, string pattern) where THub : Hub
|
||||
/// <returns>An <see cref="HubEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
|
||||
public static HubEndpointConventionBuilder MapHub<THub>(this IEndpointRouteBuilder endpoints, string pattern) where THub : Hub
|
||||
{
|
||||
return endpoints.MapHub<THub>(pattern, configureOptions: null);
|
||||
}
|
||||
|
|
@ -32,8 +32,8 @@ namespace Microsoft.AspNetCore.Builder
|
|||
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
|
||||
/// <param name="pattern">The route pattern.</param>
|
||||
/// <param name="configureOptions">A callback to configure dispatcher options.</param>
|
||||
/// <returns>An <see cref="IEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
|
||||
public static IEndpointConventionBuilder MapHub<THub>(this IEndpointRouteBuilder endpoints, string pattern, Action<HttpConnectionDispatcherOptions> configureOptions) where THub : Hub
|
||||
/// <returns>An <see cref="HubEndpointConventionBuilder"/> for endpoints associated with the connections.</returns>
|
||||
public static HubEndpointConventionBuilder MapHub<THub>(this IEndpointRouteBuilder endpoints, string pattern, Action<HttpConnectionDispatcherOptions> configureOptions) where THub : Hub
|
||||
{
|
||||
var marker = endpoints.ServiceProvider.GetService<SignalRMarkerService>();
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
e.Metadata.Add(new HubMetadata(typeof(THub)));
|
||||
});
|
||||
|
||||
return conventionBuilder;
|
||||
return new HubEndpointConventionBuilder(conventionBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
// 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.
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstraction that builds conventions that will be used for customization of Hub <see cref="EndpointBuilder"/> instances.
|
||||
/// </summary>
|
||||
public interface IHubEndpointConventionBuilder : IEndpointConventionBuilder
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>Components for providing real-time bi-directional communication across the Web.</Description>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
|
|
|
|||
Loading…
Reference in New Issue