Author : HASSAN MD TAREQ | Updated : 2020/08/02
Procedure to start new development
- Create visual studio solution
- Decide solution name
- Decide project names
- Bare minimun core for git reposity
- Delete “bin” and “obj” folders project(s)
- Add
.gitignore
to solution: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
- Create repository & put bare minimun core:
- Azure DevOps
- Github
- Gitlab (public/private)
- Add SSH key to repository
- Install Git for windows
- Open Git GUI > Help > SSH key > Generate (will ask for password > ok > ok)
- Repository Settings > Add SSH key
- Clone repository
- Add nuget packages
- EF Core Data Project
- Create domain project
- All business logic should be in domain project
IFooService
&FooService
: will be registered to DI container in Startup class- EF Core data project will be used in domain project
- UI models and (EF Core) Data Models will be seperated
- AutoMapper will be used for:
UI models <-> (EF Core) Data Models
- Create unit testing project: xUnit
Hosted option during scaffolding Blazor WebAssembly project
dotnet blazorwasm --hosted
(ordotnet blazor --hosted
)- Visual Studio Scaffolding: ASP.NET Core 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 of your site in ASP.NET Core, you can reuse that site
- No CORS issues
Explanation: tomRedox’s answer in Stack Overflow
In that case 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
Scaffolding CRUD in Visual Studio
As of 2020.07.24, VS 2019 does not support scaffolding CRUD using EF Core DbContext for Blazor.
We need to do it manually
EF Core Data Project
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