Hybrid model official guidance
[EDIT by @guardrex to change the topic ... see comment]
It would be great to have an official recommendation later for a true hybrid model like here : https://github.com/Suchiman/BlazorDualMode , so that if someone want to develop in serverside blazor and if need to switch to client later once its ready for production then can easily switch it.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: d31248d7-d2c2-1a17-3173-889a0d9bb6e8
- Version Independent ID: 6f27ff37-6b3a-57f5-353a-5cf5aabba7cf
- Content: ASP.NET Core Blazor project structure
- Content Source: aspnetcore/blazor/project-structure.md
- Product: aspnet-core
- Technology: aspnetcore-blazor
- GitHub Login: @guardrex
- Microsoft Alias: riande
What is the Blazor hosting-model counterpart to an ASP.NET application that talks to a remote SQL Server instance via System.Data.SqlClient in an WebHandler or ashx, and Ajax widgets to inject jsonified data into the UI?
@tfr888 We're working on a topic for that and have a PR in review. Blazor client-side works well with web API, but server-side is still in-design. There's a workaround approach for server-side in the PR comments. See: https://github.com/aspnet/AspNetCore.Docs/pull/12477.
btw - Your question doesn't match what this issue addresses. There's a This Page feedback button at the bottom of the topic that will open a new issue. I just mention it for future reference.
As an evangelist of Blazor from the earliest days of its development, I'd just like to chime in that this feature (enabled by the shared programming model) is the holy grail of Rapid Application Development and what I was imagining when Blazor was still client only and the Server Side Hosting model was a brand new idea, well before it was decided the Server Hosting Model would be the 1st supported release.
Initially I had envisioned that the developer would apply an Attribute to a class to inform the Blazor internals of whether the class needed to be handled by the server runtime as opposed to the browser runtime, however I've since become a greater fan of the approach identified by Danroth27 in PR 12477 where the developer registers an interface with DI, and then provides an implementation unique to each platform.
Looking forward to this feature when it lands!
The simplest approach would be to have all the application logic & components in a Razor Class Library and reference it from both a Blazor Server and Blazor WebAssembly projects. For any services, which will need to differ based on the hosting model, the interface will need to be defined in the shared project, whereas separate implementations will need to be housed in WebAssembly and Server projects.
I changed this to the Project Structure topic because I know from prior chats with DR that he'd like to keep the Hosting Models topic focused on the built-in, true hosting models. This isn't a built-in hosting model or even a project template to mention in passing. It seems to me that this is more of a constructed "project structure." Besides, we don' have another high-level location for this guidance outside of the Hosting Models and Project Structure topic, unless we create a whole new topic for this (tiny) bit of content, which doesn't make sense to me.
... also note that we should avoid "hybrid" in this context, given that there is a different thing called "Blazor Hybrid."