Skip to content

Add AddServerComponents() to Blazor Web App project template #48952

Closed

Description

@TonyHenrique

Is there an existing issue for this?

  • I have searched the existing issues

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

No response

Describe the solution you'd like

I have been using blazor for some years, but now I tried the new Blazor Web App project template and noticed that a very important call is missing:
services.AddRazorComponents().AddServerComponents()

I think that this should be included, or at least commented, in the project template:

services.AddRazorComponents()
//.AddServerComponents() // Enables interactivity
;

to make easier for new users to quickly make things work easily as it was on the previous template.

Additional context

No response

Activity

  1. ghost added
    area-blazorIncludes: Blazor, Razor Components
    on Jun 21, 2023
  2. javiercn commented on Jun 22, 2023

    @javiercn
    Member

    @TonyHenrique thanks for contacting us.

    That gets automatically included when the server option is selected as part of the template creation.

  3. TonyHenrique commented on Jun 22, 2023

    @TonyHenrique
    Author

    Hi, @javiercn ! I checked again now and used both dotnet new command and Microsoft Visual Studio Community 2022 (64-bit) - Preview (Version 17.7.0 Preview 2.0)
    and got this same template that does not even mention the .AddServerComponents()

    dotnet --list-sdks
    6.0.100-preview.7.21379.14 [C:\Program Files\dotnet\sdk]
    6.0.410 [C:\Program Files\dotnet\sdk]
    7.0.400-preview.23274.1 [C:\Program Files\dotnet\sdk]
    8.0.100-preview.5.23303.2 [C:\Program Files\dotnet\sdk]
    
    dotnet new blazor
    O modelo "Blazor Web App" foi criado com êxito.
    Este modelo contém tecnologias de outras pessoas além da Microsoft, consulte https://aka.ms/aspnetcore/8.0-third-party-notices para obter detalhes.
    
    Processando ações pós-criação...
    Restaurando C:\temp\blazor_net8\blazor_net8.csproj:
      Determinando os projetos a serem restaurados...
      C:\temp\blazor_net8\blazor_net8.csproj restaurado (em 154 ms).
    A restauração foi bem-sucedida.
    
    

    image
    image
    image

    Program.cs

    using BlazorApp3;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    builder.Services.AddRazorComponents();
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }
    
    app.UseHttpsRedirection();
    
    app.UseStaticFiles();
    
    app.MapRazorComponents<App>();
    
    app.Run();
    
  4. javiercn commented on Jun 22, 2023

    @javiercn
    Member

    @TonyHenrique we have yet to surface the server option on the template.

    It's there, just hidden. It'll be visible in preview6.

  5. TonyHenrique commented on Jun 22, 2023

    @TonyHenrique
    Author

    Got it.

    Then, please consider this to be included, or at least commented, in the project template:

    services.AddRazorComponents()
    //.AddServerComponents() // Enables blazor server interactivity
    ;
    
  6. javiercn commented on Jun 22, 2023

    @javiercn
    Member

    @TonyHenrique why is it not enough with the option in the template?

  7. TonyHenrique commented on Jun 22, 2023

    @TonyHenrique
    Author

    I think that the whole idea is converging to have a single Blazor project template that works seamlessy on server, webassembly and now also has the SSR (kind of static behaviour like a classic ASP.NET of PHP page), wich is very cool.

    Why not include the call that makes Blazor interactivity work out of the box and to not require the coder to create another project with some option to have this included?

    For example, I am used to create a new blazor project, hit the Visual Studio play button and the interactivity works. Now when trying the new template, I got surprised that I ran the new project and the interactivity did not work, so I had to manually search for and add that call AddServerComponents().

    That is why I suggested that at least it came commented on the template code.

  8. javiercn commented on Jun 22, 2023

    @javiercn
    Member

    @TonyHenrique but it's going to show up in the final version of the template, and it's likely going to be checked by default, so you'll have to remove it to be in that situation.

  9. ghost locked as resolved and limited conversation to collaborators on Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions