This page looks best with JavaScript enabled

Blazor Q/A with Tim Corey

 ·  ☕ 8 min read

There is little information about Blazor on the internet. Even less as far as enterprise / professional Blazor development is concerned. Blazor is not exactly new, but still, it feels more as an undercover platform, even today in May of 2020. This Q/A session with Tim Corey is meant to fill the gap. Tim is a software developer, consultant, trainer, and Microsoft MVP, passionate about Blazor. He runs a YouTube channel dedicated to making the process of learning software development easier.

Table of contents (click to navigate to corresponding section):

Popularity

How good is vendor support? Do you go with Devexpress or is there a smaller vendor but better support for Blazor specifically? Is anyone hiring for Blazor roles? Salary estimate? Any notable production apps written in Blazor?

Tim: Blazor is just getting started, really, since the release of Blazor Server in September 2019. That means you will not necessarily find a ton of jobs hiring specifically Blazor developers. But, how would they? They cannot ask for x years of experience in Blazor. It has been out for months, not years. However, I am seeing more of a push for current web developers to evaluate using Blazor for new projects in existing roles. So, while you may have been hired to be an MVC developer, or that might be the role you are interviewing for, you may find yourself building Blazor applications. Especially Blazor Server.

Blazor Server is the sweet spot for most web development. It provides the benefits of a client-side, SPA-like application while still having the safety and ease of development of a server-side application. It is the best of both worlds. That is why I suspect we will see a dramatic increase in the number of jobs around Blazor Server soon. It gives companies the power of a SPA with the security of a server-side app and they do not have to split their resources between C# developers and JavaScript developers. You can do it all with one language. From a cost-savings perspective, that is a win-win-win scenario, and you do not get many of those.

When it comes to third-party support, Blazor already has a lot of options. I created a video on some of the free ones and there are quite a few that I didn’t cover. The major vendors also have paid versions as well (Component One, Telerik, etc.)

Performance

From the “in-depth” conference/presentation on Youtube, Blazor has a flat list of nodes, for diffing, so it’s O(1) for lookup. Angular has a tree. Flat list should be faster so in theory Blazor should be several orders of magnitude faster than Angular. Is it the case? And still the case with Ivy (Angular 9)? What are some recent performance numbers from 2019 or 2020?

Tim: I have not done any performance evaluation of Blazor myself. I do know that the team at Microsoft did some interesting tests to evaluate Blazor Server especially, since that SignalR connection is a question a lot of people wonder about. Their results were very promising, finding that even one box can scale to thousands of users simultaneously and, of course, you can scale even greater with load-balancing and offloading of the SignalR connection to a dedicated service.

I will say that trying to compare Blazor Server to Angular will be an apples to oranges comparison. Angular is purely client-side, which means it relies on an API to get/update data. That means the site is actually two pieces. Blazor Server is both sides of that transaction. It is the API and it is the UI together so if you want to attempt a clear comparison, you need to evaluate both the API and the Angular app against just the Blazor Server app to see what performance looks like.

Unit testing in Blazor

Which articles do you recommend to get started with it? Are there multiple frameworks available? What about unit test performance for a real-world production app, say if it has 5000-10000 tests?

Tim: Blazor is just like any other C# application. The UI code is actually nicely disconnected from the UI itself, or at least it can be if architected well. In C#, if you are going to test the logic, I recommend XUnit with Moq. Since those unit test suites run in Visual Studio, you also get all the benefits of the latest versions of Visual Studio, which have really improved how unit testing is performed. Improvements like smart running of tests, running on save, instant feedback, and more. If you are going to do UI tests, you would want to use something like Selenium It isn’t something I have a lot of familiarity with (I don’t do a ton of UI testing – I find the results not worth the effort in most cases).

Coding guidelines

For Angular we have rxjs, functional programming, store pattern and others. Are there well established / recommended design patterns when writing enterprise apps in Blazor?

Tim: The great thing about Blazor is that it is just a user interface on top of an existing, long-term code base in C#. That means that most, if not all, of the existing patterns can be used with Blazor. I can take an existing MVC application in C# and replace the user interface with Blazor Server. The only thing that changes is how the UI is rendered. The business logic, data access, and more all stay the same.

When it comes to the UI-specific guidelines for Blazor, it is already built in an MVVM-like structure. That means that even the UI code is loosely coupled to the display of the data. That allows for easier testing, usage of things like dependency injection, and more.

Regarding new patterns, the biggest one will be how we separate out the code for our Razor components. Do we leave the code on the page (which is still technically a separate file as far as the compiler is concerned) or do we move the code to a separate file? I have found that it makes development easier to keep the code on the page during development and then move it to a separate file before production.

Architecture and system design

So, we do not need a separate API layer now with Blazor. Do you still recommend having it? Or having something else instead? What would be a typical / generic n-tier design you recommend starting with?

Tim: How you architect your system will depend on your specific situation (the infamous “it depends” answer). However, in general, I would recommend you start out with your UI code (Blazor) in one project and your business logic and data access in a separate project (a class library). That is a simple structure that allows for flexibility now and in the future. This, in my opinion, is the simplest solution that I would recommend. Before you move to a more complex solution, I would recommend you answer the question “what does this complexity give me” before moving forward. There are trade-offs for every decision we make. Does adding a separate library for your data access give you enough benefits to justify the additional complexity? Does adding an API give you enough additional flexibility to justify the much higher complexity and transmission cost?

In general, I love the API solution, but only if I am fairly certain that the UI will be changed out later or that I will be an additional user interfaces in the future (like a Xamarin app). Now this assumes that you are using Blazor Server. If you decide to go the Blazor Client/Web Assembly route, you will need to build an API layer. Like Angular, it has no direct connection to the database. It needs an intermediate layer of some type.

This brings up the interesting case of building your application in Blazor Server now but leaving the door open for adding Blazor WebAssembly down the road. If you want to go that route, you will want to create the API right away. That way, you can change over to Blazor WebAssembly at any point. The code would be practically the same, but you could then add features like turning your site into a progressive web app (PWA) without as much difficulty.

Continuous integration

Is there a cloud provider that can build and deploy your Blazor app in a few clicks? I understand everything is possible in Azure, but usually takes some time to figure out. A good example of user friendly UI is Netlify, I’m using it for this blog, it’s super fast and did not have issues configuring it. Big part of adoption is how easy it is to get going with new tech.

Tim: I personally use Azure DevOps for CI/CD, even if I don’t deploy to Azure. Yes, it can be fiddly to get right the first time (my first 5-10 builds are usually failed attempts), but that is to be expected. You are trying to get command line settings correct when you are used to just hitting a run button for local development. However, once you get it right, it just works, and it is rock solid.

For hosting, I have started using a service called Interserver. It costs $5/month for Blazor hosting and it includes unlimited SQL databases. That is a great option for small to medium sites. If you want to have the ability to easily scale, Azure is definitely the way to go.

Other thoughts

Tim: I do have a few videos on YouTube on Blazor Server that would be of benefit.

I also have a course on Udemy that is titled “Which ASP.NET Core” that helps you choose which ASP.NET Core project type is right for your situation by showing you all five and then building five small CRUD applications (one for each type). We also deploy all five applications to a real web host. Here is a link to the course.

Finally, I have a Blazor Server In Depth course that dives deep into how Blazor Server is designed, how to configure it, and how to use some of the advanced features in it.


Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)