Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

/// <summary>
Expand All @@ -12,13 +15,14 @@ public class ComponentTypeMetadata
/// Initializes a new instance of <see cref="ComponentTypeMetadata"/>.
/// </summary>
/// <param name="componentType">The component type.</param>
public ComponentTypeMetadata(Type componentType)
public ComponentTypeMetadata([DynamicallyAccessedMembers(Component)] Type componentType)
{
Type = componentType;
}

/// <summary>
/// Gets the component type.
/// </summary>
[DynamicallyAccessedMembers(Component)]
public Type Type { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Discovery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Primitives;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

internal class RazorComponentEndpointDataSource<TRootComponent> : EndpointDataSource
internal class RazorComponentEndpointDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent> : EndpointDataSource
{
private readonly object _lock = new();
private readonly List<Action<EndpointBuilder>> _conventions = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components.Discovery;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Routing;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Infrastructure;

Expand All @@ -20,7 +22,7 @@ public RazorComponentEndpointDataSourceFactory(
_providers = providers;
}

public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<TRootComponent>(IEndpointRouteBuilder endpoints)
public RazorComponentEndpointDataSource<TRootComponent> CreateDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent>(IEndpointRouteBuilder endpoints)
{
var builder = ComponentApplicationBuilder.GetBuilder<TRootComponent>() ??
DefaultRazorComponentApplication<TRootComponent>.Instance.GetBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Discovery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Extensions.DependencyInjection;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand All @@ -19,7 +21,7 @@ internal class RazorComponentEndpointFactory
internal void AddEndpoints(
#pragma warning restore CA1822 // It's a singleton
List<Endpoint> endpoints,
Type rootComponent,
[DynamicallyAccessedMembers(Component)] Type rootComponent,
PageComponentInfo pageDefinition,
IReadOnlyList<Action<EndpointBuilder>> conventions,
IReadOnlyList<Action<EndpointBuilder>> finallyConventions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Components.Infrastructure;
Expand All @@ -9,20 +10,21 @@
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Builder;

/// <summary>
///
///
/// </summary>
public static class RazorComponentsEndpointRouteBuilderExtensions
{
/// <summary>
///
///
/// </summary>
/// <param name="endpoints"></param>
/// <returns></returns>
public static RazorComponentEndpointConventionBuilder MapRazorComponents<TRootComponent>(this IEndpointRouteBuilder endpoints)
public static RazorComponentEndpointConventionBuilder MapRazorComponents<[DynamicallyAccessedMembers(Component)] TRootComponent>(this IEndpointRouteBuilder endpoints)
{
ArgumentNullException.ThrowIfNull(endpoints);

Expand Down Expand Up @@ -63,7 +65,7 @@ private static void AddBlazorWebJsEndpoint(IEndpointRouteBuilder endpoints)
#endif
}

private static RazorComponentEndpointDataSource<TRootComponent> GetOrCreateDataSource<TRootComponent>(IEndpointRouteBuilder endpoints)
private static RazorComponentEndpointDataSource<TRootComponent> GetOrCreateDataSource<[DynamicallyAccessedMembers(Component)] TRootComponent>(IEndpointRouteBuilder endpoints)
{
var dataSource = endpoints.DataSources.OfType<RazorComponentEndpointDataSource<TRootComponent>>().FirstOrDefault();
if (dataSource == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand Down Expand Up @@ -31,7 +33,7 @@ public abstract IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(

internal static void AddEndpoints(
List<Endpoint> endpoints,
Type rootComponent,
[DynamicallyAccessedMembers(Component)] Type rootComponent,
IEnumerable<RouteEndpointBuilder> renderModeEndpoints,
IComponentRenderMode renderMode,
List<Action<EndpointBuilder>> conventions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

/// <summary>
Expand All @@ -12,13 +15,14 @@ public class RootComponentMetadata
/// Initializes a new instance of <see cref="RootComponentMetadata"/>.
/// </summary>
/// <param name="rootComponentType">The component type.</param>
public RootComponentMetadata(Type rootComponentType)
public RootComponentMetadata([DynamicallyAccessedMembers(Component)] Type rootComponentType)
{
Type = rootComponentType;
}

/// <summary>
/// Gets the component type.
/// </summary>
[DynamicallyAccessedMembers(Component)]
public Type Type { get; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand All @@ -21,7 +23,7 @@ public interface IComponentPrerenderer
/// <returns>A task that completes with the prerendered content.</returns>
ValueTask<IHtmlAsyncContent> PrerenderComponentAsync(
HttpContext httpContext,
Type componentType,
[DynamicallyAccessedMembers(Component)] Type componentType,
IComponentRenderMode renderMode,
ParameterView parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Discovery;

Expand Down Expand Up @@ -35,6 +37,7 @@ public required IReadOnlyList<string> RouteTemplates
/// <summary>
/// Gets or sets the page type.
/// </summary>
[DynamicallyAccessedMembers(Component)]
public required Type PageType { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Discovery;

Expand All @@ -20,7 +22,7 @@ internal class PageComponentInfo
/// <param name="metadata">The page metadata.</param>
internal PageComponentInfo(
string displayName,
Type type,
[DynamicallyAccessedMembers(Component)] Type type,
string route,
IReadOnlyList<object> metadata)
{
Expand All @@ -38,6 +40,7 @@ internal PageComponentInfo(
/// <summary>
/// Gets the page type.
/// </summary>
[DynamicallyAccessedMembers(Component)]
public Type Type { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Compile Include="$(RepoRoot)src\Shared\ClosedGenericMatcher\ClosedGenericMatcher.cs" LinkBase="FormMapping" />
<Compile Include="$(ComponentsSharedSourceRoot)src\CacheHeaderSettings.cs" Link="Shared\CacheHeaderSettings.cs" />
<Compile Include="$(ComponentsSharedSourceRoot)src\DefaultAntiforgeryStateProvider.cs" LinkBase="Forms" />
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />

<Compile Include="$(SharedSourceRoot)PropertyHelper\**\*.cs" />

Expand Down
10 changes: 8 additions & 2 deletions src/Components/Endpoints/src/RazorComponentEndpointHost.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Components.Rendering;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand All @@ -19,8 +21,12 @@ internal class RazorComponentEndpointHost : IComponent
{
private RenderHandle _renderHandle;

[Parameter] public Type ComponentType { get; set; } = default!;
[Parameter] public IReadOnlyDictionary<string, object?>? ComponentParameters { get; set; }
[Parameter]
[DynamicallyAccessedMembers(Component)]
public Type ComponentType { get; set; } = default!;

[Parameter]
public IReadOnlyDictionary<string, object?>? ComponentParameters { get; set; }

public void Attach(RenderHandle renderHandle)
=> _renderHandle = renderHandle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Components.Web.HtmlRendering;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

internal partial class EndpointHtmlRenderer
{
private static readonly object ComponentSequenceKey = new object();

protected override IComponent ResolveComponentForRenderMode(Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode)
protected override IComponent ResolveComponentForRenderMode([DynamicallyAccessedMembers(Component)] Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode)
{
var closestRenderModeBoundary = parentComponentId.HasValue
? GetClosestRenderModeBoundary(parentComponentId.Value)
Expand Down Expand Up @@ -50,14 +52,14 @@ protected override IComponent ResolveComponentForRenderMode(Type componentType,

public ValueTask<IHtmlAsyncContent> PrerenderComponentAsync(
HttpContext httpContext,
Type componentType,
[DynamicallyAccessedMembers(Component)] Type componentType,
IComponentRenderMode prerenderMode,
ParameterView parameters)
=> PrerenderComponentAsync(httpContext, componentType, prerenderMode, parameters, waitForQuiescence: true);

public async ValueTask<IHtmlAsyncContent> PrerenderComponentAsync(
HttpContext httpContext,
Type componentType,
[DynamicallyAccessedMembers(Component)] Type componentType,
IComponentRenderMode? prerenderMode,
ParameterView parameters,
bool waitForQuiescence)
Expand Down Expand Up @@ -98,7 +100,7 @@ public async ValueTask<IHtmlAsyncContent> PrerenderComponentAsync(

internal async ValueTask<PrerenderedComponentHtmlContent> RenderEndpointComponent(
HttpContext httpContext,
Type rootComponentType,
[DynamicallyAccessedMembers(Component)] Type rootComponentType,
ParameterView parameters,
bool waitForQuiescence)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand Down Expand Up @@ -65,7 +66,7 @@ private void SetHttpContext(HttpContext httpContext)

internal static async Task InitializeStandardComponentServicesAsync(
HttpContext httpContext,
Type? componentType = null,
[DynamicallyAccessedMembers(Component)] Type? componentType = null,
string? handler = null,
IFormCollection? form = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

namespace Microsoft.AspNetCore.Components.Endpoints;

Expand All @@ -21,14 +23,15 @@ internal class SSRRenderModeBoundary : IComponent
{
private static readonly ConcurrentDictionary<Type, string> _componentTypeNameHashCache = new();

[DynamicallyAccessedMembers(Component)]
private readonly Type _componentType;
private readonly IComponentRenderMode _renderMode;
private readonly bool _prerender;
private RenderHandle _renderHandle;
private IReadOnlyDictionary<string, object?>? _latestParameters;
private string? _markerKey;

public SSRRenderModeBoundary(Type componentType, IComponentRenderMode renderMode)
public SSRRenderModeBoundary([DynamicallyAccessedMembers(Component)] Type componentType, IComponentRenderMode renderMode)
{
_componentType = componentType;
_renderMode = renderMode;
Expand Down
Loading