Can we create a blazor server application without SignalR?

Viewed 2527

I'm currently testing Blazor, and I'm trying to understand it.

So far, I created a webassembly blazor with a .net core backend with Web API, it works really well. Then I created a server-side blazor, with SignalR. It works well, but I wanted to try using API instead of SignalR. My idea is that I should separate the client-side and server-side in two separate projects (maybe with a shared project like the wasm example). I also find out that SignalR are not REST API.

I'm wondering, does it make sense? VS2019 has template for Blazor server with SignalR and Blazor client (wasm) with the option to add .net core hosted (Web API REST). I guess there would be a template for Blazor Server with Web API (without SignalR) if it made sense?

Best Regards,

twl

1 Answers

I don't think that you can, or that it's even useful to do it. The official documentation here: https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-models?view=aspnetcore-3.1#blazor-server states

A Blazor Server app is built on top of ASP.NET Core SignalR.

UI updates, event handling, and JavaScript calls are handled over a SignalR connection.

How would you do it with an api? The use of the api, calls for the traditional web development techniques.

Each browser screen (browser tab or iframe) that is connected to a Blazor Server app uses a SignalR connection.

But I have an API

Cool, you can use your api. No one is forbidding you to make api calls from your server blazor code. The server blazor is responsible for updating your ui. You can leave it that way and when you want data, call the api from server blazor code.

Even better, to get rid of that extra hop, create new projects as dll libraries that will handle your business logic and consume them in server blazor.

Related