Wasm-template w client-side-only reg. service (and server-side part) [.Net 8]

Hello

I am a solution architect evaluating Radzen Blazor for quite a large enterprise solution.

The solution must create a hybrid standalone web app (Wasm Pwa) but with some server-side services, controllers, pages and auth. The pages rendered client-side must use a DataService/DbContext that is innately local and cannot be used or even created server-side.

In our PoC evaluation we create a solution using your Blazor Studio’s .Net 8 WebAssembly interactivity template with PWA. We scaffold the pages etc (that will become what we would call server-side pages, even though they might often be client-side rendered too) with a server-side Db. Then create some pages manually* (that will become what we would call client-side pages, and can only be rendered client-side) using a client-side-only registered DbContextFactory, i.e. is not also registered server-side.
(* actually not created manually per se but using another Radzen project of the Server template to scaffold the pages, models and service then copying those to new folders in the Wasm client-side project of the first (real) Radzen solution, and register a DbContextFactory instead of the scaffolded DataService, in OnIntializedAsync we get the factory and create the DataService instances for the pages’ code-behind)

Runtime this works almost well enough. The client-side Wasm pages will get the client-side registered DbContextFactory and render pages. Visiting server-side pages also works fine. And auth on top of all. The problem being that as soon as the SignalR connection is disrupted (or if it’s some other Blazor reason) the server will try to pre-render (guessing a bit) the client side pages which of course fails on the injection of the client-side-only registered service which is not present in the server side runtime (and cannot be).

Bottom line question:
Is there a workaround for this? (Like preventing the “client-side” pages from being server-side rendered entirely)

As an option we have tried to create a standard Microsoft Wasm Pwa template which is completely stand-alone client-side. That works perfectly with the local service of course but comes with other downsides to this app project such as:
A) no full application end-to-end RAD scaffolding support like with Radzen
B) no out of box server side part with OData endpoints, controllers or auth etc meaning a lot of work

Is there a way to adapt the Radzen Blazor Wasm template to meet the requirements described above (supporting a client-side-only registered service/dbcontext/factory)? Even though it might require some hefty refactoring.

We would greatly appreciate you expert insights of your product and templates here. Even pointing us in a promising direction would be valuable. I hope we can stick with Radzen Blazor in the end.

Thanks

Hi @Puzzler,

I guess you can disable prerendering for those pages:

@rendermode InteractiveAuto(prerender: false)

The other option is this: ASP.NET Core Blazor render modes | Microsoft Learn

Hi @korchev

Thanks!
Adding
@rendermode @(new InteractiveRenderMode(prerender: false)) to client-side pages and will report back

Thanks again @korchev for your always so rapid replies and support!

After changing server’s App.razor to

head>…HeadOutlet @rendermode=“new InteractiveWebAssemblyRenderMode(prerender: false)” />

and

body>…Routes @rendermode=“new InteractiveWebAssemblyRenderMode(prerender: false)” />

this somewhat unorthodox solution actually works a bit better.
We no longer get an smack-in-your-face-exception from server-side rendering when it is missing the DI:d service. Instead pages are rendered ok componentwise after a SignalR reset but all without data. The DbContext seem to be reset but not reloaded.

So we now have other challenges (we think) with making our custom DbContextFactory handle the event and effects of the SignalR loosing its connection and the service worker kicking in perhaps.