.NET MAUI - Will it Wow Me?
I have been thinking about playing with .NET MAUI for months now and I finally decided to take the plunge this weekend and see if I could rebuild at least a part of my Hybrid MVC/Blazor Server template application using .NET MAUI. I specifically wanted to create a template that allowed me to build a mobile, desktop, and web application all using only Blazor WASM for the user interface. I further wanted to have only one codebase and I wanted to implement Identity, EF Core (sqlite), and use JWT tokens for the client(s) to communicate with the Web API. So the translation of all of that is I just wanted a basic application where users could register, login, logout and do the usual boilerplate Blazor stuff (the counter and fetch data defaults).
What I found after several hours of poking around is that it is indeed possible to make this happen and other than the initial load speed (which is still pretty slow for Blazor WASM), it is really quite the slick way to build something that targets all environments. Here is what the example I did looks like on each device:
The Blazor WASM web application
There is really very little that needed to be changed from my Blazor Server code to work with the Blazor WASM web client. The main difference was just that I needed a secured Web API project.
Here is what the same application looks like as a Windows desktop application:
You might wonder if it is any different at all from the web application. If it wasn’t for the typical dialog window with the minimize, maximize, and close in the top right you really wouldn’t know the difference. Which is actually perfect because that is exactly what I was going for.
Last, but not least here is what it looks like on the Android Emulator:
It’s surprisingly easy to target each device. I just have to switch startup projects and I am done. If you are interested, here’s a somewhat expanded look at the structure of my solution.
领英推荐
I have the UI in a folder that contains three projects. The Core project is where I keep all of the Razor/Blazor pages and components. I then have the boilerplate code necessary to load those for Mobile (which includes Desktop) and the Web. I have the models and a couple of shared services in the Shared project and finally I have the WebApi for actually handling all of the Identity work (managing application users and dealing with the JWT tokens).
In order to embark on this journey I used a combination of my own Blazor Server template, plus this git repository https://github.com/bradystroud/MauiBlazorTemplate, and finally I used the following to add Identity with all the JWT code https://www.youtube.com/watch?v=2V2tQU1kEOM. There was quite a bit of fussing necessary to get the Shared class library doing everything that I wanted it to do across all of the devices but in the end it worked very well.
So will I be using Blazor WASM for my next project?
That is a very good question! The answer is that it entirely depends as always on what the application needs to do. The biggest issue I have with Blazor WASM is the slow load times which I think most users are just going to not put up with at all. I’ll be looking at the various options for speeding that up (which I think will require splitting the app some with some server pre-rendering). That said, I do think that I could overcome the speed issues. Here is a more comprehensive list of the downsides for me personally:
Disadvantages of .NET MAUI and Blazor WASM
Advantages of .NET MAUI and Blazor WASM
So, I think the question of whether I would use this template for my next project or not is best answered by saying that I wouldn’t rule it out. It is a viable solution, but I do think I would be very careful to manage expectations of any users and/or stakeholders before going down this path. It has a little ways to go to get to the same place that Angular and React are right now or even MVC/Razor/Blazor Server. That said, my order of preference right now is my Hybrid MVC/Blazor Server template and in second place is my new .NET MAUI Blazor WASM template. All things considered that’s pretty good for something that I slapped together over the weekend. Showing yet again how powerful Blazor is and how it excels at rapid prototyping and building out of MVP’s. What do you think about .NET MAUI and Blazor WASM? I would love to hear about your experiences with it too (just drop a note in the comments of this post)! Happy coding! May we all be wowed by new technologies every day!