blazor

2025-12-07 0 481

Building a PhotoSharing Application with Blazor Web Assembly Hosted, Web API, gRPC and Duende Identity Server

We\’re going to build a simple web site where people can post pictures and comments.

  • Everyone can browse existing pictures and comments.
  • Only authenticated users can upload new pictures and comments.
  • Only a picture owner can edit or delete a picture.
  • Only a comment owner can delete or update a comment.

We are going to build 3 parts.

  • The FrontEnd, a Blazor Client Web Application paired with its own ASP.NET Core Web Host.
  • The Backend, built with .NET 7.0, will consist of
    • A REST service for the managing of the pictures
    • A gRPC service for the comments
  • The Identity Provider will be our own Duende project.

1.1 – FrontEnd Client

  • Blazor Client
  • HTML 5
  • CSS 3
  • Open Id Connect Client

This project will interact with the user through a browser by dinamically constructing an HTML user interface and will talk its own server by using gRPC Web and HttpClient.

1.2 – Backend For Frontend (BFF)

  • ASP.Net Core Web Host
  • YARP
  • Duende.Bff.Yarp

This project hosts and serves the Blazor Client application. It also acts as a reverse proxy to forward the calls to the REST and gRpc backends.

2.1 – Photos REST Service

  • .NET 7 Web API Controller
  • Entity Framework Core 7.0
  • SqLite Database
  • Duende Client Authentication

2.2 – Comments gRPC Service

  • .NET 7 gRPC Service
  • Entity Framework Core 7.0
  • SqLite Database
  • Duende Client Authentication

These projects will be responsible to store the data on the server and respond to the client requests through http, json and protobuf.

  1. Authentication Server
    • Identity Server 4 (Duende)
    • Entity Framework Core

This project will take care of the authentication part. It will issue JWT tokens that will be used by the client application to gain access to the services.

What you already need to know:

  • C#
  • HTML 5
  • CSS 3

What you\’re going to learn:

  • REST
  • gRPC
  • Blazor
  • ASP.NET Core 7.0 Web API Controller
  • ASP.NET Core 7.0 gRPC Service
  • Entity Framework Core 7.0
  • Swagger / OpenAPI
  • CORS
  • YARP
  • Authentication and Authorization
  • OAuth 2 and Open Id Connect
  • Identity Server 4 (Duende)
  • Simple Authorization
  • Resource Owner Authorization
  • CLEAN Architecture
  • Unit Testing with bUnit
  • Javascript interoperability

Before you begin

At the time of the writing of this tutorial, .NET Core 7.0 can be used only with Visual Studio 2022. It is recommended that you install the latest version of Visual Studio 2022 in order to work with .NET Core 7.0.

  • Install the latest version of Visual Studio 2022 with the ASP.NET and web development workload
  • Install .NET Core 7.0 by downloading the .NET Core 7.0 SDK

You may want to go to the getting started documentation for an updated set of instructions.


Our workflow

We are going to follow some simple steps. Each step will focus on one task and will build on top of the previous step. We will start with simple projects that will become more and more complex along the way. For example, we will not focus on authentication and authorization at first. We will add it at a later step.

How to follow this tutorial

If you start from Lab01 and follow each readme.md, you can complete each lab and continue to the following one using your own code. No need to open neither the Start nor the Solution folders provided in this repo.

  • Start folders are the starting points of each step.
  • Solution folders are the final versions of each step, given to you just in case you want to check what your project is supposed to become at the end of each lab.

What you have to do is to open a Start folder corresponding to the lab you want to try (Lab01/Start in order to begin from scratch) and follow the instructions you find on the readme.md file. When you are done, feel free to compare your work with the solution provided in the Solution folder.

To START

  1. Open the Labs folder
  2. Navigate to the Lab01 subfolder
  3. Navigate to the Start subfolder
  4. Follow the instructions contained in the readme.md file to continue

If you want to see the final application

Create the Photos REST Service DataBase

  • Open Lab15\\Solution\\blazor\\PhotoSharingApplication\\PhotoSharingApplication.sln in Visual Studio
  • Build the Solution
  • Ensure that you have multiple startup projects:
    • IdentityServer
    • Rest
    • gRPC
    • Frontend.Server

Start the application

To Logon

  • Username: alice
  • Password: Pass123$

Or

  • Username: bob
  • Password: Pass123$

One last note before we begin

I assume you\’re a C# programmer interested in building a web application. Depending on how old you are, you may have already used asp, aspx, mvc and / or razor pages and now you want to try blazor. You may be already familiar with HTML and CSS and maybe you even played with some javascript framwork such as Angular, React or Vue.

I am going to link a ton of documentation about web concepts and technologies, so don\’t worry if you\’re not a web developer expert, you can learn everything along the way. You should at least be fluent in C#, though, or this tutorial will be hard to follow. Most of the code that we\’re going to write will be, in fact, C#. We are also going to write some HTML, but that\’s easy to learn so that is not going to be a problem.

The Labs

  • Lab 01 – The Blazor Frontend
    • Exploring the structure of a Blazor Web Assembly project and creating our first page
  • Lab 02 – Frontend: Additional Views
    • CLEAN Architecture
    • Dependency Injection
    • Using additional Blazor Libraries through NuGet Packages
    • Routes
    • Data Binding
    • Event Handling
  • Lab 03 – Frontend: Styling the UI with MatBlazor
    • Material Design
    • MatBlazor
    • Layout Pages
  • Lab 04 – Frontend – Razor Class Libraries and Components
    • Creating a Razor Class Library
    • Using a Razor Class Library from within a project
    • Razor Components
    • Parent and Child Components
    • Properties
    • EventCallbacks
  • Lab 05 – Backend: Web API with ASP.NET Core 7.0 and Visual Studio 2022
    • REST Protocol
    • Asp.NET Core Web Api
    • Controllers
    • Actions
    • Routes
    • Binding
    • Entity Framework Core
    • JSON
    • Swagger / OpenAPI
  • Lab 06 – Frontend: Connecting with the Backend
    • HttpClient
    • HttpClient Configuration
    • GetFromJsonAsync
    • PostAsJsonAsync
    • PutAsJsonAsync
    • DeleteAsync
    • ReadFromJsonAsync
    • CORS
    • YARP
  • Lab 07 – Frontend: Comments
    • More CLEAN architecture
    • More Components
  • Lab 08 – Backend: gRPC with ASP.NET Core 7.0 and Visual Studio 2022
    • More CLEAN architecture
    • gRPC
    • protobuf
    • gRPC in Asp.Net Core
  • Lab 09 – Frontend: Connecting with the Backend
    • gRPC Web
    • gRPC Client Web in .NET Core
    • Configuration
    • CORS
    • YARP
  • Lab 10 – Security: Authentication and Authorization
    • Duende Identity Server
    • Configuring the REST Service for JWT Bearer Authentication
    • Configuring the gRPC Service for JWT Bearer Authentication
    • Configuring the Blazor Client for JWT Bearer Authentication
    • Simple Authorization with the Authorize Attribute
    • Retrieving and passing JWT Bearer Tokens by using the Duende.Bff.Yarp framework
  • Lab 11 – Security: Resource Based Authorization
    • AuthorizationService
    • Policies
    • Requirements
    • Handlers
  • Lab 12 – Performance Optimization
    • Entity Framework Table Splitting
    • Download a File from a REST Web Api Service
    • Browser Caching
  • Lab 13 – Validation
    • Data Annotations
    • Fluent Validation in the Core Service
    • Fluent Validation in ASP.NET Core REST Service
    • Fluent Validation in Blazor with Blazored.FluentValidation
  • Lab 14 – Unit Testing Blazor Components with bUnit
    • Unit Testing
    • Mocking
    • xUnit
    • Moq
    • bUnit
  • Lab 15 – Blazor / Javascript interoperability
    • IJSRuntime
    • Call a JavaScript function in ASP.NET Core Blazor
    • Call .NET methods from JavaScript functions in ASP.NET Core Blazor
    • Blazor JavaScript isolation and object references
    • Leaflet
    • exif.js

下载源码

通过命令行克隆项目:

git clone https://github.com/scolapicchioni/blazor.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 blazor https://www.zuozi.net/31368.html

JavaLearn
上一篇: JavaLearn
PDFtoPrinter
下一篇: PDFtoPrinter
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务