dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.01k forks source link

Provide a component instance capture in RouteView (aka new RouteView.Instance property) #41106

Open jhudler opened 2 years ago

jhudler commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

No response

Describe the solution you'd like

DynamicComponent already has the Instance property, enabling access to the rendered component instance.

Is there anything against having such feature in RazorView component as well? Code modification proposal would be:

// src/Components/Components/src/RouteView.cs
public class RouteView : IComponent
{

+   /// <summary>
+   /// Gets rendered component instance.
+   /// </summary>
+   public object? Instance { get; private set; }

// (...)

    private void RenderPageWithParameters(RenderTreeBuilder builder)
    {
        builder.OpenComponent(0, RouteData.PageType);

//       (...)

+       builder.AddComponentReferenceCapture(2, component => Instance = component);
        builder.CloseComponent();
    }
}

Additional context

In my case, I need to access the rendered component instance after all parameters were set (for our centralized state preservation implementation). Creating my own router is a possibility, but I'll need to fallback to reflection to mimic today's RouteView behavior (e.g.: the QueryParameterValueSupplier is internal and my approach will not be not future-safe).

If suggestion approved, I can provide a pull request.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mkArtakMSFT commented 2 years ago

Thanks for contacting us and your willingness to send a PR. For now we're not sure whether this will be a useful feature for a large number of customers. Hence we would like to keep this issue on our backlog to accumulate more feedback. Depending on the feedback we receive here in the future we'll choose either to do something here or will close this.

ghost commented 11 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.