Introduction to Razor class libraries

Completed

By using Razor class libraries, you can share and reuse user-interface components between Blazor applications. In this module, you'll focus on building and sharing components for Blazor applications.

Diagram showing a Razor class library being used in the Blazor server instance and Blazor WebAssembly.

Example scenario

Let's suppose that you work for a consulting firm, where you build web applications for various clients. You have a collection of web features, such as modal window components, that you make available to your clients. To save time, you want to be able to reuse these features across applications.

By using Razor class libraries, you can share the features across the applications that you build for your customers.

Screenshot of an example modal window component that can be shared across Blazor applications.

What will we be doing?

In this module, you'll create a Razor class library to accomplish the following goals:

  • Present a modal dialog box with default theming
  • Use and customize the modal dialog in a Blazor application
  • Package the modal window dialog for use with other applications

What is the main goal?

By the end of the module, you'll be able to design a modal window component that you can share and customize across other Blazor applications.

Prerequisites

  • Familiarity with HTML, CSS, and JavaScript web development.
  • Novice ability to write C# code.
  • The .NET 8.0 SDK installed.
  • An integrated development environment (IDE). This module uses Visual Studio Code.

Note

This module uses the .NET CLI (Command Line Interface) and Visual Studio Code for local development. After completing this module, you can apply the concepts using Visual Studio (Windows) or continued development using Visual Studio Code (Windows, Linux, and macOS).

This module uses the .NET 8.0 SDK. Ensure that you have .NET 8.0 installed by running the following command in your preferred command terminal:

dotnet --list-sdks

Output similar to the following example appears:

6.0.317 [C:\Program Files\dotnet\sdk]
7.0.401 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

Ensure that a version that starts with 8 is listed. If none is listed or the command isn't found, install the most recent .NET 8.0 SDK.