Make RouteOptions.EndpointDataSources internal (#9708)
This commit is contained in:
parent
1845706a71
commit
8ce7bd171d
|
|
@ -319,7 +319,6 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
public RouteOptions() { }
|
public RouteOptions() { }
|
||||||
public bool AppendTrailingSlash { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public bool AppendTrailingSlash { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
public System.Collections.Generic.IDictionary<string, System.Type> ConstraintMap { get { throw null; } set { } }
|
public System.Collections.Generic.IDictionary<string, System.Type> ConstraintMap { get { throw null; } set { } }
|
||||||
public System.Collections.Generic.ICollection<Microsoft.AspNetCore.Routing.EndpointDataSource> EndpointDataSources { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
|
||||||
public bool LowercaseQueryStrings { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public bool LowercaseQueryStrings { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
public bool LowercaseUrls { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public bool LowercaseUrls { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
public bool SuppressCheckForUnhandledSecurityMetadata { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public bool SuppressCheckForUnhandledSecurityMetadata { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,28 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using Microsoft.AspNetCore.Routing.Constraints;
|
using Microsoft.AspNetCore.Routing.Constraints;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Routing
|
namespace Microsoft.AspNetCore.Routing
|
||||||
{
|
{
|
||||||
public class RouteOptions
|
public class RouteOptions
|
||||||
{
|
{
|
||||||
public ICollection<EndpointDataSource> EndpointDataSources { get; internal set; }
|
private IDictionary<string, Type> _constraintTypeMap = GetDefaultConstraintMap();
|
||||||
|
private ICollection<EndpointDataSource> _endpointDataSources;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection of <see cref="EndpointDataSource"/> instances configured with routing.
|
||||||
|
/// </summary>
|
||||||
|
internal ICollection<EndpointDataSource> EndpointDataSources
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Debug.Assert(_endpointDataSources != null, "Endpoint data sources should have been set in DI.");
|
||||||
|
return _endpointDataSources;
|
||||||
|
}
|
||||||
|
set => _endpointDataSources = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether all generated paths URLs are lower-case.
|
/// Gets or sets a value indicating whether all generated paths URLs are lower-case.
|
||||||
|
|
@ -48,8 +63,6 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public bool SuppressCheckForUnhandledSecurityMetadata { get; set; }
|
public bool SuppressCheckForUnhandledSecurityMetadata { get; set; }
|
||||||
|
|
||||||
private IDictionary<string, Type> _constraintTypeMap = GetDefaultConstraintMap();
|
|
||||||
|
|
||||||
public IDictionary<string, Type> ConstraintMap
|
public IDictionary<string, Type> ConstraintMap
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// 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 System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
@ -27,6 +28,37 @@ namespace Microsoft.AspNetCore.Routing.Tests
|
||||||
Assert.Equal("TestRouteConstraint", accessor.Value.ConstraintMap["foo"].Name);
|
Assert.Equal("TestRouteConstraint", accessor.Value.ConstraintMap["foo"].Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EndpointDataSources_WithDependencyInjection_AddedDataSourcesAddedToEndpointDataSource()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
services.AddOptions();
|
||||||
|
services.AddRouting();
|
||||||
|
var serviceProvider = services.BuildServiceProvider();
|
||||||
|
|
||||||
|
var endpoint1 = new Endpoint((c) => Task.CompletedTask, EndpointMetadataCollection.Empty, string.Empty);
|
||||||
|
var endpoint2 = new Endpoint((c) => Task.CompletedTask, EndpointMetadataCollection.Empty, string.Empty);
|
||||||
|
|
||||||
|
var options = serviceProvider.GetRequiredService<IOptions<RouteOptions>>().Value;
|
||||||
|
var endpointDataSource = serviceProvider.GetRequiredService<EndpointDataSource>();
|
||||||
|
|
||||||
|
// Act 1
|
||||||
|
options.EndpointDataSources.Add(new DefaultEndpointDataSource(endpoint1));
|
||||||
|
|
||||||
|
// Assert 1
|
||||||
|
var result = Assert.Single(endpointDataSource.Endpoints);
|
||||||
|
Assert.Same(endpoint1, result);
|
||||||
|
|
||||||
|
// Act 2
|
||||||
|
options.EndpointDataSources.Add(new DefaultEndpointDataSource(endpoint2));
|
||||||
|
|
||||||
|
// Assert 2
|
||||||
|
Assert.Collection(endpointDataSource.Endpoints,
|
||||||
|
ep => Assert.Same(endpoint1, ep),
|
||||||
|
ep => Assert.Same(endpoint2, ep));
|
||||||
|
}
|
||||||
|
|
||||||
private class TestRouteConstraint : IRouteConstraint
|
private class TestRouteConstraint : IRouteConstraint
|
||||||
{
|
{
|
||||||
public TestRouteConstraint(string pattern)
|
public TestRouteConstraint(string pattern)
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
|
||||||
template: "{controller=Home}/{action=Index}/{id?}");
|
template: "{controller=Home}/{action=Index}/{id?}");
|
||||||
});
|
});
|
||||||
|
|
||||||
var routeOptions = appBuilder.ApplicationServices
|
var endpointDataSource = appBuilder.ApplicationServices
|
||||||
.GetRequiredService<IOptions<RouteOptions>>();
|
.GetRequiredService<EndpointDataSource>();
|
||||||
|
|
||||||
Assert.Empty(routeOptions.Value.EndpointDataSources);
|
Assert.Empty(endpointDataSource.Endpoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue