GithubHelp home page GithubHelp logo

blazor-surveys's Introduction

blazor-surveys

Example .NET 5.0 application that explores integrating SignalR with a Blazor WebAssembly application, as well as some of the latest C# features like record types.

To do so, it implements a very simple site for creating and participating in surveys:

  • Users can define surveys which are listed in the home page. Any new survey added is notified to any other user via SignalR.
  • Users can participate in a survey and their vote/answer is notified to any other user viewing the same survey in real time via SignalR

Installation

Make sure you have the .NET 5.0 SDK installed (download here) and clone this repo.

You will see a solution with 3 folders/projects:

  • The Client folder contains the Blazor WebAssembly project. This is the actual Blazor application.
  • The Server folder contains a standard ASP.NET application with 2 purposes:
    • host the client-side Blazor application, by allowing the browser to load the client assets like JS, CSS, WebAssembly modules, etc
    • provide the backend API and SignalR hubs, with the logic to create and interact with the surveys. This is no different from a normal ASP.NET Web API
  • The Shared folder contains a standard .NET library project. Sharing code between the client and server is one of possible benefits of using Blazor, this project contains models shared between the Client and Server projects.

One you have cloned the repo, use standard dotnet commands/tooling to build and run. For example, from the root folder:

# restore dependencies
dotnet restore
# run the project
dotnet watch -p Server run

Interesting features

Since this project is mostly an exercise to explore some of Blazor WebAssembly, SignalR and C# 9 features, its worth highlighting a few interesting bits:

  • Since the real time features are non essential for the application, the initalization of the client SignalR connection in App.razor is non-blocking. This means if unable to establish the SignalR connection, the client app can still load and function via the regular HTTP API
  • Both pages Index.razor and SurveyDetails.razor will unsubscribe from SignalR events when navigating away
  • The shared models use the new C# 9 record types where possible
  • The model for adding a survey uses data annotation to implement validation both client and server side
  • The AddSurvey.razor page shows how to validate a form (including nested models), and how to update blazor's defaults to use bootstrap styling
  • The IExpirable interfaces uses C# 8 implemented properties to provide read-only properties with the minutes/seconds remaining. The interface is then used by various record types.
  • The blazor component SurveyExpiration.razor displays the remaining time for a survey and uses a timer to refresh the UX every second

Reference

blazor-surveys's People

Contributors

daniel-jimenezgarcia-ow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.