News

On Blazor Component Reusability - From Day 0

"We want to try to design from Day One, even Day Zero, with reusability in mind," says Blazor expert Allen Conway in imparting his expertise to an audience of hundreds in an online tech event on Tuesday.

Highlighted by Conway, an app modernization consultant at Xebia, this week's event published by Visual Studio Magazine is titled "Blazor Beyond the Basics: Advanced Techniques and Innovations" and is now available for on-demand replay thanks to the sponsor, Developer Express.

Throughout his presentation, Conway emphasized the importance of designing Blazor components with reusability in mind, which is one of the oft-mentioned benefits of Blazor, providing:

  • Modular Code Structure: Encapsulates logic and UI in self-contained units, making components easy to update, debug, and maintain.
  • Faster Development: Reusable components speed up coding by eliminating redundancy and enabling rapid assembly of new features.
  • Consistent Design: Ensures a uniform look and behavior across the application, reducing inconsistencies and enhancing the user experience.
  • Customizability: Parameters allow components to adapt to different scenarios without rewriting code, increasing flexibility.
  • Cross-Project Sharing: Components can be exported to libraries or packages, saving time by reusing proven functionality across projects.
Finding Reusability
[Click on image for larger view.] Finding Reusability (source: Allen Conway).

Conway framed reusability in the context of general web components.

"So all the popular frameworks and libraries, including in Blazor, the way that we look at this is that we take views that we have in our applications and we break them down into small chunks of functionality. And so in days of past, oftentimes, we too closely associated a particular route or a view or an area in the application with a single file or build -- essentially a monolithic building, monolithic view."

Besides not being testable, that approach comes with a low level of reuse to high coupling, so Blazor and other frameworks try to break down views into small pieces that have reusability, also backed by things like modern web data binding.

"This will help also increase how much reusability we have within our components," he said. "And we want to try to design from Day One, even Day Zero, with reusability in mind. In general, designing with reusability, even if it's not tagged as something for reuse, comes with a positive byproduct of testability and maintainability."

Conway delved deeper into reusability, discussing keys that start off with that planning ahead from the earliest stages.

Keys To Component Reusability
[Click on image for larger view.] Keys To Component Reusability (source: Allen Conway).

"If you can plan ahead for application design, to break it down into those small, those puzzle pieces, that is an excellent start," he said. "If not, take a second set of eyes to your existing application -- if it's getting difficult to maintain, if you've had that pattern of one route is a single component, try to break that down into smaller components. They should work well on an island, and the way you do that is with component interaction via the myriad of ways that we can pass data along between the different components.

"You can do that again, from a parent to child relationship, passing the needed data so that components can encapsulate and do one thing and one thing well. We have Blazor functionality like render fragment and templated. You can also go even farther with making generic components .... there's a lot of opportunity in there for that reuse reusability, as well as those sound coding patterns and testing, because if you keep all that in mind with your C# and .NET code, that also will promote reusable components."

Along with Blazor component reusability, Conway also discussed in detail subjects like styling, content projection, responsive components, component logic design and much more.

Also, Don Wibier, a technical evangelist at DevExpress, was on hand to showcase third-party Blazor wares from that company, which is listed by Microsoft as a community contributor in its official Blazor documentation, along with others.

"Probably all of you have already been working or playing with ChatGPT or Copilot or some other generative AI tool," Wibier said in introduction. "But wouldn't it be cool to incorporate this technology in your own applications so that you can deliver it to your end users. Well, this is what this session is all about. It's called 'Chatting with Your own Data with DevExpress AI-powered Controls.' " He went on to highlight "a couple of really cool features that we will be releasing in our 24.2 release." Again, check out that replay for more on products from DevExpress, which always tops our annual Visual Studio Magazine Reader's Choice Awards in many categories.

Of course, one benefit of attending such presentations live is the ability to ask questions of the expert presenters, and with that in mind, one upcoming dev-related event includes the Dec. 10 Microsoft Ignite 2024: Top Announcements and Takeaways presented by sister publication RedmondMag, which is also putting on:

More information straight from Redmond's mouth can be found in:

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