Moving the components
We are going to move the components that we can share between the Blazor Server and Blazor WebAssembly projects. This is one of the amazing powers of Blazor; the only thing that differs between the two projects is the hosting model. The code can remain the same (for most cases).
In our case, we made sure to have different ways of accessing the data just to cover those possibilities as well, but we will come back to that in the next section.
First, we need to create a new project and move some files. To do this, perform the following steps:
- Right-click on the
MyBlog
solution and select Add | New project. - Search for
Razor
and you should find a template called Razor Class Library. Select that template and click Next. - Name the project
MyBlog.Shared
, leave the location as is (it should be in the correct folder already), and then click Next. - Select Target Framework .NET 5.0 (Current) and make sure Support pages and views are unchecked. Then...