Skip to content

[Blazor|Mvc] Make Microsoft.AspNetCore.Mvc.ViewFeatures.IComponentRenderer public #21666

@JvanderStad

Description

@JvanderStad

I have my own version of ComponentTagHelper

https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.TagHelpers/src/ComponentTagHelper.cs#L101

var componentRenderer = ViewContext.HttpContext.RequestServices.GetRequiredService<IComponentRenderer>();
var result = await componentRenderer.RenderComponentAsync(ViewContext, ComponentType, RenderMode, _parameters);

However Microsoft.AspNetCore.Mvc.ViewFeatures.IComponentRenderer is not marked as public.
To work around this, I use reflection.

var type = Type.GetType("Microsoft.AspNetCore.Mvc.ViewFeatures.IComponentRenderer, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60");
var componentRenderer = ViewContext.HttpContext.RequestServices.GetRequiredService(type);

var method = type.GetMethod("RenderComponentAsync");
Parameters[nameof(CascadingAuthenticationStateComponent.ComponentType)] = ComponentType.AssemblyQualifiedName;

var result = await (Task<IHtmlContent>)method.Invoke(componentRenderer, new object[] { ViewContext, typeof(CascadingAuthenticationStateComponent), RenderMode, Parameters });

please make IComponentRenderer public.

https://github.com/dotnet/aspnetcore/blob/602cb1dea59751a1297d674cddf7f0729c23e6ca/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/IComponentRenderer.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-prerenderingIssues related to prerendering blazor componentsseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions