10

I want to develop an SPA project by Blazor technology.

Due to complexity of debugging the Blazor Web-assembly application, I would like to first create it as a server-side app, and then later change it to a Web-assembly application app.

Is this possible? If so, after I have successfully gotten the Server-side Blazor project to work, what changes will I need to make, to get the same functionality working with the WebAssembly project?

Also, are there any particular approaches or technologies I should avoid in my Server-side Blazor project, because they have no equivalent when using WebAssembly?

Greg Gum
  • 25,941
  • 27
  • 127
  • 194
  • 1
    It's a good idea. I have shared serverside-hosted code (pages, components, ...) in another project that I include in both. – dani herrera Mar 07 '20 at 15:16
  • 2
    You can even work on them in parallel, see the first few minutes of [this video](https://youtu.be/QnBYmTpugz0) – Henk Holterman Mar 08 '20 at 06:38
  • 1
    The question was closed as 'opiniated', make it more a how-to question to prevent or reverse that. – Henk Holterman Mar 08 '20 at 06:44
  • @HenkHolterman , thanks for your great recommendation .. – Mohamad Jalalian Mar 08 '20 at 08:02
  • 1
    I summarized the steps in [this answer](https://stackoverflow.com/a/60361395/60761). – Henk Holterman Mar 08 '20 at 19:10
  • OK, so I edited the question so it can be reopened, and then either answered, or closed as a duplicate to Henk's answer. However, it now seems like a possibly different question from the one Henk answered. – Developer63 Mar 31 '20 at 00:40
  • Yes, it can be done. The only technical issue is that Blazor Web Assembly requires the use of an API (Controllers) whereas Blazor server accesses server resources directly (without going through a Controller, as it's already runing on the server). So all such code would have to be updated. Along with this, the WA template from Visual Studio creates three projects, whereas Server is only one. So the server project would have to be divided up between client, server, and shared projects. – Greg Gum Nov 15 '20 at 12:01
  • Also note that debugging is now working in Blazor WebAssembly, so it's no longer a reason to use Server over WA. – Greg Gum Nov 15 '20 at 12:03
  • @hardkoded, I have edited this question so it is not opinion based. Can you please re-open? – Greg Gum Nov 15 '20 at 12:10

1 Answers1

3

For the most part, your Blazor components should be able to migrate from Server to Webassembly with few or no changes.

If your Blazor Server application doesn't require data from outside your application (e.g. database calls), and it doesn't use any APIs that aren't supported in the browser (e.g. System.Security.Cryptography), then you may be able to migrate to Blazor Webassembly without any changes to your components.

If your Blazor Server application does require data from outside the browser, then those services will need to be hosted elsewhere and called from your components via Http requests (see Call a web API from ASP.NET Core Blazor). There are a couple of good options for your Blazor Webassembly back-end, the most common of which is the Blazor Webassembly hosted template.enter image description here

If you'd rather serve your Webassembly app as a static web application, you can instead move your back-end services to a serverless function application. There are a variety of options for that, the most convenient of which (in my opinion) is using Azure Static Web Apps with .NET and Blazor

HillPhelmuth
  • 121
  • 3