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

Subscribe on YouTube