dotnet / Scaffolding

Code generators to speed up development.
MIT License
624 stars 224 forks source link

Content for CRUD/EF scaffolding of Razor components #2473

Open danroth27 opened 1 year ago

danroth27 commented 1 year ago

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:

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:

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:

Sample generated code

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

@mkArtakMSFT @javiercn @stevesandersonms @DamianEdwards

deepchoudhery commented 1 year ago

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

SteveSandersonMS commented 9 months ago

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.

tjorvenK commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

@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 !