This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for specifying filters on page models.
Fixes #6334
- Loading branch information
Showing
50 changed files
with
2,755 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/IPageRouteModelConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
|
||
namespace Microsoft.AspNetCore.Mvc.ApplicationModels | ||
{ | ||
/// <summary> | ||
/// Allows customization of the of the <see cref="PageRouteModel"/>. | ||
/// </summary> | ||
public interface IPageRouteModelConvention | ||
{ | ||
/// <summary> | ||
/// Called to apply the convention to the <see cref="PageRouteModel"/>. | ||
/// </summary> | ||
/// <param name="model">The <see cref="PageRouteModel"/>.</param> | ||
void Apply(PageRouteModel model); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/IPageRouteModelProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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. | ||
|
||
namespace Microsoft.AspNetCore.Mvc.ApplicationModels | ||
{ | ||
/// <summary> | ||
/// Builds or modifies an <see cref="PageRouteModelProviderContext"/> for Razor Page routing. | ||
/// </summary> | ||
public interface IPageRouteModelProvider | ||
{ | ||
/// <summary> | ||
/// Gets the order value for determining the order of execution of providers. Providers execute in | ||
/// ascending numeric value of the <see cref="Order"/> property. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Providers are executed in an ordering determined by an ascending sort of the <see cref="Order"/> property. | ||
/// A provider with a lower numeric value of <see cref="Order"/> will have its | ||
/// <see cref="OnProvidersExecuting"/> called before that of a provider with a higher numeric value of | ||
/// <see cref="Order"/>. The <see cref="OnProvidersExecuted"/> method is called in the reverse ordering after | ||
/// all calls to <see cref="OnProvidersExecuting"/>. A provider with a lower numeric value of | ||
/// <see cref="Order"/> will have its <see cref="OnProvidersExecuted"/> method called after that of a provider | ||
/// with a higher numeric value of <see cref="Order"/>. | ||
/// </para> | ||
/// <para> | ||
/// If two providers have the same numeric value of <see cref="Order"/>, then their relative execution order | ||
/// is undefined. | ||
/// </para> | ||
/// </remarks> | ||
int Order { get; } | ||
|
||
/// <summary> | ||
/// Executed for the first pass of building <see cref="PageRouteModel"/> instances. See <see cref="Order"/>. | ||
/// </summary> | ||
/// <param name="context">The <see cref="PageRouteModelProviderContext"/>.</param> | ||
void OnProvidersExecuting(PageRouteModelProviderContext context); | ||
|
||
/// <summary> | ||
/// Executed for the second pass of building <see cref="PageRouteModel"/> instances. See <see cref="Order"/>. | ||
/// </summary> | ||
/// <param name="context">The <see cref="PageRouteModelProviderContext"/>.</param> | ||
void OnProvidersExecuted(PageRouteModelProviderContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageHandlerModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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 System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.ApplicationModels | ||
{ | ||
/// <summary> | ||
/// Represents a handler in a <see cref="PageApplicationModel"/>. | ||
/// </summary> | ||
[DebuggerDisplay("PageHandlerModel: Name={" + nameof(PageHandlerModel.MethodName) + "}")] | ||
public class PageHandlerModel : ICommonModel | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="PageHandlerModel"/>. | ||
/// </summary> | ||
/// <param name="handlerMethod">The <see cref="System.Reflection.MethodInfo"/> for the handler.</param> | ||
/// <param name="attributes">Any attributes annotated on the handler method.</param> | ||
public PageHandlerModel( | ||
MethodInfo handlerMethod, | ||
IReadOnlyList<object> attributes) | ||
{ | ||
MethodInfo = handlerMethod ?? throw new ArgumentNullException(nameof(handlerMethod)); | ||
Attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); | ||
|
||
Parameters = new List<PageParameterModel>(); | ||
Properties = new Dictionary<object, object>(); | ||
} | ||
|
||
/// <summary> | ||
/// Creats a new instance of <see cref="PageHandlerModel"/> from a given <see cref="PageHandlerModel"/>. | ||
/// </summary> | ||
/// <param name="other">The <see cref="PageHandlerModel"/> which needs to be copied.</param> | ||
public PageHandlerModel(PageHandlerModel other) | ||
{ | ||
if (other == null) | ||
{ | ||
throw new ArgumentNullException(nameof(other)); | ||
} | ||
|
||
MethodInfo = other.MethodInfo; | ||
HandlerName = other.HandlerName; | ||
HttpMethod = other.HttpMethod; | ||
MethodName = other.MethodName; | ||
|
||
Page = other.Page; | ||
|
||
// These are just metadata, safe to create new collections | ||
Attributes = new List<object>(other.Attributes); | ||
Properties = new Dictionary<object, object>(other.Properties); | ||
|
||
// Make a deep copy of other 'model' types. | ||
Parameters = new List<PageParameterModel>(other.Parameters.Select(p => new PageParameterModel(p) { Handler = this })); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="System.Reflection.MethodInfo"/> for the handler. | ||
/// </summary> | ||
public MethodInfo MethodInfo { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the HTTP method supported by this handler. | ||
/// </summary> | ||
public string HttpMethod { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the handler method name. | ||
/// </summary> | ||
public string HandlerName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a descriptive name for the handler. | ||
/// </summary> | ||
public string MethodName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the seqeunce of <see cref="PageParameterModel"/> instances. | ||
/// </summary> | ||
public IList<PageParameterModel> Parameters { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="PageApplicationModel"/>. | ||
/// </summary> | ||
public PageApplicationModel Page { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<object> Attributes { get; } | ||
|
||
/// <inheritdoc /> | ||
public IDictionary<object, object> Properties { get; } | ||
|
||
MemberInfo ICommonModel.MemberInfo => MethodInfo; | ||
} | ||
} |
Oops, something went wrong.