Author : MD TAREQ HASSAN | Updated : 2021/01/24
Scaffolding options for Blazor WebAssembly
Hosted option
- Visual Studio Scaffolding: ASP.NET Core hosted (bottom right, check box)
- dotnet CLI:
dotnet blazorwasm --hosted
(ordotnet blazor --hosted
) - What is it?
- A projected hosted with ASP.NET Core backing API’s
- If you’re writing an API or SignalR hub to send and receive data from your Blazor client
- Why to use it?
- If you’re also writing the backend Web/API app in ASP.NET Core
- No CORS issues
- Explanation: tomRedox’s answer in Stack Overflow
- When you don’t use the ‘hosted’ option
- Standalone Blazor WebAssembly doesn’t read/write from any server, or if it only talks to 3rd party APIs or an existing REST API
- You can simply publish your Blazor project and then take the files from the release folder and host them in any site
Progressive web application
- Making Blazor WebAssembly application PWA compatible
- PWA details
Scaffolding Blazor Server CRUD app
- As of today (last checked: January 2021)
- VS 2019 does not support scaffolding CRUD using EF Core DbContext for Blazor Server the way we can scaffold ASP.Net core app
- We need to do it manually
- We need to create EF Core Data project and that Data project will be used in our CRUD app.
- Create Database and insert data (you can use Vidual Studio LocalDB)
- EF Core Database first approach
- Configurations for DbContext (in Startup class + DbContext class)
- Build the data project to make sure everything is working.
- Using Data Project in Blazor App
- Blazor App > Right Click > Build Dependencies > Project Dependencies…
- Select the Data Project (Checked) > OK
- EF Core Nuget Package
- Blazor App > Right > Manage Nuget Packages…
- Browse > Search: “Microsoft.EntityFrameworkCore.SqlServer” > Install
- Or PMC:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
- Build the Blazor App > Data project model classes will be available to use