Blazor data access strategies


In this video we will discuss the options we have to access server-side data from a Blazor application.

One way to build a data driven blazor application is by using the following architecture. With this architecture, the client which is usually the browser calls the Blazor server application. Blazor server application runs on the server. A SignalR connection is established between the client and the blazor application for exchanging information.

blazor data access layer

For data, the Blazor application can talk directly to a database server by using entity framework core or some other data access framework. However, use this approach only when you know the Blazor application will always be running on the server and in the future there is no need to convert the Blazor server application to Blazor WebAssembly application. This is because EF core cannot run on the client browser. So if you want to convert this Blazor server application to a Blazor WebAssembly application a lot of rework and code chnage is required.

However, this is an option if you know your Blazor application will always be running on the server. 

In this course we will be using a different approach. For the application that we will be building we will use the following architecture. 

With this architecture we have a RESTful service between the Blazor application and the Database. REST stands for REpresentational State Transfer and it is based on open standards. If you are new to REST, we will discuss what it is in our upcoming videos. So, Blazor application calls the RESTful service. The RESTful service calls the Database using Entity Framework Core. 

blazor application architecture

We will be building the RESTful service using ASP.NET Core MVC. Since the RESTful service will be running server-side on a .NET core enabled server we will have access to all server-side resources and data including the capability to run Entity Framework Core code.

The obvious benefit of this approach is, the blazor code we write to consume a RESTful service can be used with both the hosting models i.e Blazor Server and Blazor WebAssembly. It is easy (ie. with minimal changes) we can convert a Blazor server project to Blazor WebAssembly project and vice-versa.

In our next video, we will discuss What is REST.

Slides

blazor data access strategies

blazor project architecture

blazor app architecture





© 2020 Pragimtech. All Rights Reserved.