Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Design] Blazor United: Layering architecture #46393

Closed
mkArtakMSFT opened this issue Feb 1, 2023 · 1 comment
Closed

[Design] Blazor United: Layering architecture #46393

mkArtakMSFT opened this issue Feb 1, 2023 · 1 comment
Assignees
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-full-stack-web-ui Full stack web UI with Blazor Priority:1 Work that is critical for the release, but we could probably ship without
Milestone

Comments

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Feb 1, 2023

This is the initial architecture diagram of how we plan to layer things:

Architecture

  • Microsoft.AspNetCore.Components.Web will handle HTML rendering.
    • Will take a dependency on System.Text.Encodings.Web.
    • Will be host agnostic (won't reference ASP.NET Core nor register any service in DI)
  • Microsoft.AspNetCore.Components.Endpoints
    • Will provide IComponentBuilder AddComponents() and IEndpointComponentBuilder endpoints.MapComponents()
    • Will provide "standalone" support for static rendering by writing to the response directly.
      • We might revisit this based on performance measurements and refactor ViewBuffers into a common layer/shared source.
  • Microsoft.AspNetCore.Mvc.ViewFeatures will depend on Microsoft.AspNetCore.Components.Endpoints to support rendering components as tag helpers.
  • Microsoft.AspNetCore.Components.Server will provide support for rendering server components as part of server rendered components apps.
  • Microsoft.AspNetCore.Components.Webassembly.Server will provide support for rendering webassembly components as part of server rendered components apps.
  • Rendering components outside of HttpContext will be supported by Microsoft.AspNetCore.Components.Web.
    • Using it will potentially require providing any service that is needed.

Scenarios

Server side rendered components application (like MVC/RazorPages)

services.AddComponents();

builder.MapComponents()

Server side rendered components application with support for Server components

services.AddComponents()
  .AddServerComponents();

builder.MapComponents();

Server side rendered components application with support for Webassembly components

services.AddComponents()
  .AddWebassemblyComponents();

builder.MapComponents();

Server side rendered components application with support for Webassembly and Server components

services.AddComponents()
  .AddServerComponents()
  .AddWebassemblyComponents();


builder.MapComponents();

Full Blazor Server app

services.AddServerSideBlazor();

builder.MapComponents();

MainLayout.razor

@render Server
...
<Router>
</Router>
...

Full Webassembly (hosted) app

services.AddComponents().AddWebassemblyComponents();

builder.MapComponents();

MainLayout.razor

@render Webassembly
...
<Router>
</Router>
...

Full auto app

services.AddComponents()
    .AddWebassemblyComponents()
    .AddServerComponents();

builder.MapComponents();

MainLayout.razor

@render Auto
...
<Router>
</Router>
...

Open questions

  • Mapping "standalone" webassembly apps (index.html as entry point)
    • We can still figure out the routes if we want by default.
    • MapFallback still exists as a "fallback".
  • Can we get rid of App.razor within index.html?
    • Based on what we are proposing for "Blazor server apps", we can potentially do the same thing for webassembly.
    • Replace builder.RootComponents.Add<App>("#app"); with builder.RootComponents.AddComponentPages("#app");
      • Render the layout, have the code inside the layout render the router (or figure out a more custom way of doing this).
  • On the cases for Full Blazor Server/Webassembly we'll have to figure out how to provide context for what typically goes inside <Found>/<NotFound>
  • How do we handle multiple "united" apps (imagine 2 webassembly apps that get "upgraded" to blazor-united) and hosted on a parent server project.

Further issues tasks breakdown

  • Provide a primitive inside Microsoft.AspNetCore.Components.Web for rendering output to HTML.
    • This is in charge of writing the output from a component into a stream/pipewriter.
    • We need to figure out what options this primitive must have (things like quiescence, and so on).
    • We will need an extensibility point for handling rendering webassembly and server components.
    • Needs design.
  • Create Microsoft.AspNetCore.Components.Endpoints (name TBD) to hold the functionality for Server-Side Rendering components.
    • Add an extension method for registering component services AddRazorComponents.
      • Register the services needed for performing server-side rendering on DI.
    • Add an extension method for registering endpoints for Razor Component Pages.
      • We have to design the details about how we integrate with endpoint routing.
  • Refactor component rendering on MVC to depend on the Microsoft.AspNetCore.Components.Endpoints implementation.
  • Add an extension method on Microsoft.AspNetCore.Components.Server that plugs in support for Server Components on top of Microsoft.AspNetCore.Components.Endpoints.
    • We will add the endpoints to the collection.
    • Similar for Microsoft.AspNetCore.Components.WebAssembly.Server.
@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one area-blazor Includes: Blazor, Razor Components Priority:1 Work that is critical for the release, but we could probably ship without feature-full-stack-web-ui Full stack web UI with Blazor labels Feb 1, 2023
@mkArtakMSFT mkArtakMSFT added this to the .NET 8 Planning milestone Feb 1, 2023
@javiercn javiercn self-assigned this Feb 15, 2023
@javiercn
Copy link
Member

@SteveSandersonMS SteveSandersonMS changed the title We can perform basic CRUD operations on a completely SSR Razor Components app [Design] Blazor United: Layering architecture Mar 2, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-full-stack-web-ui Full stack web UI with Blazor Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

No branches or pull requests

2 participants