Q&A

How to Build Fast and Reusable Blazor Code with Microsoft's Jeffrey T. Fritz

Building reusable components with Microsoft's full-stack web-dev framework, Blazor, relieves the drudgery of writing the same code over and over again.

Reusable components in Blazor -- which allows for web development in C# instead of JavaScript -- can help developers make their projects simpler and their code processes more productive.

Microsoft even offers a Build reusable components with Blazor learning module that shows how to build a Razor class library that contains Blazor components, package a Razor class library for use in other Blazor applications, and reference a Razor class library in a Blazor application and use its components.

[Click on image for larger view.] Blazor Class Library Usage (source: Microsoft).

For even more detail, however, coders can't do much better than the full stack web development track at the big, five-day Visual Studio Live! developer conference taking place next month in Nashville.

There, attendees can pick and choose from many Blazor-focused presentations ranging from 20-minute "fast focus" events to full-day hands-on labs, including:

  • Introduction to Blazor
  • Building Enterprise Blazor Apps Using CSLA.NET
  • Microsoft Blazor Top to Bottom
  • Build Your First Application with Blazor
  • Building Fast and Reusable Code with Blazor

For the latter, we caught up with Microsoft's Jeffrey T. Fritz from the .NET team to find out more about the subject of his Building Fast and Reusable Code with Blazor presentation, a 75-minute event scheduled for 3 p.m. on Tuesday, May 16.

VisualStudioMagazine: How can reusable components in Blazor help make projects simpler and code processes more productive?
Fritz: The Blazor user-interface framework is now available on the web and .NET MAUI frameworks, and these components give you that block of user-interface code that can be easily reused with no additional coding between every platform. That means a lot less re-writing, copying and pasting, and a lot more guarantee that you're going to have a consistent look and feel across your systems.

What are some of the most often-used reusable components, or ones you find most useful?
The .NET Component vendors are quickly ramping up their product offerings, with some really extensive control sets available from folks like DevExpress, Progress, SyncFusion and more. I've been using the Progress components with an application that I've been building on my live Twitch streams and have been quite successful at extending and formatting them to meet my needs. There are open source component libraries available as well, and I would recommend the MudBlazor components to folks looking for a free option.

What are some techniques that developers can use to create reusable components that can be widely used without too much specific customization needed for different use cases?

"Start by moving that block of HTML and Razor that you keep writing into its own file with a '.razor' extension."

Jeffrey T. Fritz, Program Manager, Microsoft

Start by moving that block of HTML and Razor that you keep writing into its own file with a ".razor" extension. Replace the locations you were using that HTML and Razor with a call to your new component. That's all you need to start. You can get fancier by introducing parameters and isolated stylesheets later.

Inside the Session

What: Beyond the Basics – Building Fast and Reusable Code with Blazor

When: May 16, 3 p.m. - 4:15 p.m.

Who: Jeffrey T. Fritz, Program Manager, Microsoft

Why: Learn how to stop writing the same code over and over again.

Find out more about Visual Studio Live!, taking place May 15-19 in Nashville

How can reusable Blazor components improve unit testing?
When you're writing unit tests for Blazor, you want to test the smallest units of user-interface possible and these components make it easier to isolate potential complexities by reducing the noise around your pages for the isolated feature that you actually need to test.

Is your .NET team at Microsoft eating its own Blazor reusable components dog food?
We are! We have a handful of web sites that we maintain for the .NET live video streams and events that use Blazor and re-use components to shorten our development and maintenance tasks.

With AI transforming software development, can tools like GitHub Copilot be put to use in creating reusable Blazor components?
It is amazing to me how quickly I can now build and re-use components when Copilot is able to generate markup quickly for me or help put C# code into my components that delivers exactly what I need without me wasting keystrokes. Copilot is a great tool for all .NET developers in Visual Studio and Visual Studio Code.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube