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

Content for CRUD/EF scaffolding of Razor components #2473

Open
danroth27 opened this issue Jun 30, 2023 · 5 comments
Open

Content for CRUD/EF scaffolding of Razor components #2473

danroth27 opened this issue Jun 30, 2023 · 5 comments
Milestone

Comments

@danroth27
Copy link
Member

danroth27 commented Jun 30, 2023

This issue covers delivering scaffolders for building Razor components that are analogous to the existing scaffolders for Razor Pages and EF Core that exist today. These scaffolders are server specific and are generally not intended for client scenarios (Blazor WebAssembly or Blazor Hybrid). Admittedly this violates our principle that Blazor components should typically be hosting model agnostic. But the alternative is to generate components based on a custom data access abstraction that has implementations for both server and client including any required server API endpoints, which would be non-trivial.

Starting with an existing entity model class, there are two scaffolders to select from:

  • Blazor components using Entity Framework
  • Blazor components using Entity Framework (CRUD)

The CRUD scaffolder is a shorthand for creating pages for all five templates (Create, Delete, Details, Edit, List) supported by the non-CRUD scaffolder.

The "Blazor components using Entity Framework" scaffolder has the following options:

  • Razor component name: The name of the specific component to generate
  • Template: Select one of Create, Delete, Details, Edit, List
  • URL: The URL path for the page
  • Model class: Select an available model class
  • DbContext class: Select an existing DbContext or create a new one. The appropriate packages and startup configuration code should be applied to project for EF Core based on the user's selection.
  • Database provider: Select an available EF Core database provider when creating a new DbContext: SQL Server, SQLite, PostgreSQL, Azure Cosmos DB
  • Use a layout component: Select from available layout components (inherit from LayoutComponentBase). A note should be added saying "(Leave empty to use the default layout)".

The "Blazor components using Entity Framework (CRUD)" scaffolder generates all of the template pages in one go. It has the same options as the "Blazor components using Entity Framework" scaffolder with the following exceptions:

  • No Template option
  • No URL option
  • Add URL prefix option: The URL prefix to be used for all the generated pages (Blazor doesn't support folder-based routing conventions like Razor Pages does).

Sample generated code

I've converted the scaffolded content for Razor Pages to Blazor components: https:/danroth27/BlazorScaffolding. There are a number of limitations in Blazor that we need to address:

@mkArtakMSFT @javiercn @SteveSandersonMS @DamianEdwards

@deepchoudhery
Copy link
Member

Cool will keep track of this and see what items I can create for the upcoming .NET 8 preview 7.

@SteveSandersonMS
Copy link
Member

The scaffolded content assumes static server rendering, but the app might be setup with an interactive router. We are still working through how we want to handle scenarios like this for .NET 8.

Ideally the scaffolded pages would work in either static SSR or InteractiveServer modes without any code changes. Since the same data access code would work both ways, this seems like it should be possible.

Of course, InteractiveWebAssembly is different because of forcing an API layer. I can certainly understand not wanting to support that in the short term.

@danroth27 danroth27 changed the title [DRAFT] Content for CRUD/EF scaffolding of Razor components Content for CRUD/EF scaffolding of Razor components Oct 7, 2023
@tjorvenK
Copy link

tjorvenK commented Feb 5, 2024

The issue described in here prevents me from using the scaffolded ui, after updating to .net 8.
Is there any new information available, for a possible static ssr support for the components? Or an alternative workaround? :)

@danroth27
Copy link
Member Author

The issue described in here prevents me from using the scaffolded ui, after updating to .net 8. Is there any new information available, for a possible static ssr support for the components? Or an alternative workaround? :)

@tjorvenK For a .NET 8 workaround, you can dynamically in code set the render mode of the router to be Static for specific request paths. It's not a pretty solution, but it is possible. The default identity UI included in the Blazor Web App template uses this technique when the app has global interactivity enabled. We plan to address this issue to provide a better solution in .NET 9.

@tjorvenK
Copy link

tjorvenK commented Feb 5, 2024

@tjorvenK For a .NET 8 workaround, you can dynamically in code set the render mode of the router to be Static for specific request paths. It's not a pretty solution, but it is possible. The default identity UI included in the Blazor Web App template uses this technique when the app has global interactivity enabled. We plan to address this issue to provide a better solution in .NET 9.

@danroth27 Thank you for the quick answer, I found the example you mentioned and I am excited for .NET 9 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants