Latest / DevQuestions with Tim Corey / 187 What Web Framework Should I Use For My C# Project?
Transcript
- 0:00SPEAKER_01: Welcome to the Dev Questions Podcast with Tim Corey.
- 0:03SPEAKER_01: Join us each episode as we tackle the questions you are asking about a career in software development, understanding the industry, and new technology.
- 0:12SPEAKER_01: If you're just starting out or you want to grow stronger as a developer, this is the place to get your questions answered.
- 0:19SPEAKER_01: Now, here's your host, expert developer and online educator, Tim Corey.
- 0:25SPEAKER_02: What web framework should I use for my C Sharp project?
- 0:29SPEAKER_02: When building a new web project, there are a lot of options to choose from.
- 0:33SPEAKER_02: Each option has its benefits and each option has its downsides.
- 0:38SPEAKER_02: Not only that, in the past few months, there have been some major changes that shift those pros and cons around.
- 0:46SPEAKER_02: So in this episode of Dev Questions, we're going to address what's the best web framework to choose for a C sharp developer.
- 0:54SPEAKER_02: Now, if you have a question, go to suggestions.imtimcorey and ask it there.
- 0:59SPEAKER_02: All right, so which one is the best?
- 1:02SPEAKER_02: Well, I can't give you the one right choice.
- 1:06SPEAKER_02: You probably know that by now, since it absolutely depends on your situation.
- 1:13SPEAKER_02: Now, when I say it depends, I don't just mean, well, you know, we're using this code because it's a lot more than that.
- 1:19SPEAKER_02: It's about your team, it's about your company, it's about your company history, it's about there's so many variables that it really does depend on your situation.
- 1:31SPEAKER_02: But I'm going to give you the answer today to where to start.
- 1:37SPEAKER_02: Where should be your starting point and why.
- 1:41SPEAKER_02: So if you're new to web development and you're starting off with a new web development project, and your back-end code is getting written in C, you should heavily consider using Blazor for your front end.
- 1:57SPEAKER_02: I would say this is the default starting point for all new web development for C Sharp developers.
- 2:03SPEAKER_02: It's just a place to start.
- 2:05SPEAKER_02: And then you would choose when not to use it based upon some criteria.
- 2:10SPEAKER_02: We're going to talk about that.
- 2:12SPEAKER_02: So it used to depend more on the specific situation, but that's less and less true now.
- 2:19SPEAKER_02: So let's talk about why you might choose Blazor as your default starting point, as well as when you might choose Angular, React, or View for your friend.
- 2:29SPEAKER_02: I'll also cover why I don't recommend MVC or Razor pages anymore for new projects.
- 2:36SPEAKER_02: So let's start with Blazor.
- 2:39SPEAKER_02: What are the reasons why I say I think Blazor is the right choice to start from?
- 2:45SPEAKER_02: The choice where you say, this is the starting point, and we're going to choose this unless there's a good reason not to.
- 2:52SPEAKER_02: So number one is that you can reuse existing code.
- 2:57SPEAKER_02: So libraries, code patterns, helper methods, all these things you already have for your backend can be used in your front end as well.
- 3:07SPEAKER_02: So code reuse is a big deal for developers.
- 3:10SPEAKER_02: This is going to help you be faster as a developer.
- 3:14SPEAKER_02: Number two, you can reuse the existing language expertise of your team.
- 3:19SPEAKER_02: So you're already building in C sharp.
- 3:22SPEAKER_02: Well, you can reuse that expertise for your front end as well.
- 3:26SPEAKER_02: There's no context switching.
- 3:29SPEAKER_02: The idea that you start in one language, your back end, and build in a different language for your front end can be difficult on a team because now you're trying to go deep in two different languages instead of one language.
- 3:43SPEAKER_02: It means you're a little shallower in both than if you just chose one.
- 3:48SPEAKER_02: So reusing the existing language expertise really helps you be better as a team with your project and write better code.
- 3:58SPEAKER_02: Number three, you can reuse the existing packaging and deployment systems.
- 4:05SPEAKER_02: So you don't have to use npm and ESLint and ES Build and all these other tools when you're already using NuGet and.NET Build and all the rest of the.NET stuff.
- 4:20SPEAKER_02: So you don't have to bring in two separate systems to do essentially the same job, but just for different languages.
- 4:28SPEAKER_02: Number four, you can reuse the existing tooling.
- 4:31SPEAKER_02: So if you're already using Visual Studio, you don't have to switch over to VS Code or another editor in order to do the front-end stuff.
- 4:39SPEAKER_02: You don't have to have separate worlds for both.
- 4:42SPEAKER_02: You can have one world that does both.
- 4:45SPEAKER_02: You get to use one editor better than trying to switch between two and confusing which shortcuts work where.
- 4:53SPEAKER_02: Number five, you have little lock-in when you're choosing Blazor now.
- 5:00SPEAKER_02: So you're going to start with a certain idea for your website.
- 5:05SPEAKER_02: Maybe you decide, you know what, we want to have a server-side website like you would normally have with MVC or Razor pages.
- 5:12SPEAKER_02: You can start there.
- 5:14SPEAKER_02: But then when your boss comes to you six months from now and says, we really want to have some interactivity on this particular section, no problem.
- 5:23SPEAKER_02: You can add that client side interactivity where needed.
- 5:27SPEAKER_02: Or maybe you decide to start on the client side where you want to have this whole interactive website, but you find out there's certain places where you don't need that interactivity.
- 5:38SPEAKER_02: Well, you don't have to have it, which means that you reduce the overhead of those certain pages.
- 5:43SPEAKER_02: So instead of locking into one specific way of doing things, you are able to change over time.
- 5:51SPEAKER_02: Now, this is where if we're on contrast, if we start with an Angular React or View, you're saying we're going to do a single page application, client-side application that all runs on the user's browser.
- 6:06SPEAKER_02: That's kind of locked into one way of doing things.
- 6:09SPEAKER_02: Now, that's a great way, and there's a lot of great options there, but you're locked in.
- 6:15SPEAKER_02: So if you want the efficiency and the SEO benefits of having some server side only pages, well, it's a little harder to do when your site is fully locked in with client side.
- 6:29SPEAKER_02: With Blazor, you don't have that lock-in.
- 6:31SPEAKER_02: You can change.
- 6:32SPEAKER_02: And not just change up front, you can change over time.
- 6:37SPEAKER_02: A year from now, two years from now, you can adjust how your site works based upon what you need then as opposed to what you thought you would need two years ago.
- 6:49SPEAKER_02: That's a really important thing for software development to be able to change over time.
- 6:55SPEAKER_02: Now, number six, using Blazor is easier to debug because you're not debugging across language barriers.
- 7:04SPEAKER_02: So if you have a backend that's in C sharp, well, that's going to be your API written in C sharp, and you know, you've got all that code.
- 7:13SPEAKER_02: But then if somebody has some kind of bug happen, well, is it in the JavaScript code or is it in the API code?
- 7:21SPEAKER_02: Well, you have to traverse that path.
- 7:24SPEAKER_02: And it's not impossible.
- 7:25SPEAKER_02: You can absolutely do it.
- 7:26SPEAKER_02: People do it all the time, but it's easier when it's C sharp code in the front end, C sharp code in the back end, you can follow that path more easily from start to finish to figure out where the bug is.
- 7:39SPEAKER_02: Now, number seven, you can still use the entire JavaScript ecosystem with Blazor.
- 7:46SPEAKER_02: This is something people often have a misunderstanding of.
- 7:50SPEAKER_02: They say, well, if you choose Blazor, then you're missing out on all the packages that are out there for JavaScript.
- 7:57SPEAKER_02: No, you're not.
- 7:58SPEAKER_02: You have access to the same libraries and systems in Blazor as you would in Angular.
- 8:06SPEAKER_02: You can drop in tools to help you with the various pieces that maybe already are built in JavaScript.
- 8:14SPEAKER_02: Now, there might be ways to do it better in C sharp since you're using Blazor, but you don't have to reinvent the wheel all the time.
- 8:23SPEAKER_02: Number eight, you're set up for potentially creating native mobile and desktop applications using.NET MAUI.
- 8:31SPEAKER_02: So if you're already building your site in Blazor, well, then you can use Blazor Hybrid with.NET MAUI to take that same UI and put it into your a desktop app that works on Mac or Windows, or a mobile app that works in iOS and Android.
- 8:51SPEAKER_02: So you can deploy the site as a native application as well as having it be a web application.
- 9:03SPEAKER_02: It's not 100%, but it's really high in that percentage.
- 9:07SPEAKER_02: So there's a lot of benefits of working with Blazor.
- 9:11SPEAKER_02: And I think the big thing here is the reusability, the reusing the tooling and the code itself and your skills and the environment you set up in, the all the rest of the stuff around Blazor, but then also the long-term flexibility, the long-term ability to change or grow your application as needed as opposed to being locked in to one way of doing things.
- 9:41SPEAKER_02: So let's look at why you might want to choose a JavaScript framework.
- 9:47SPEAKER_02: Because again, it does depend.
- 9:50SPEAKER_02: There are times when I'd recommend a JavaScript framework over a Blazor framework.
- 9:57SPEAKER_02: So, number one, if you already have code written in that framework, then yeah, you'd probably want to stay there.
- 10:04SPEAKER_02: So it'd probably be easier to continue on in that given framework because you're already down the road in that framework.
- 10:13SPEAKER_02: It's not like you want to throw everything out and start over.
- 10:16SPEAKER_02: That can be very, very expensive.
- 10:19SPEAKER_02: So if you're already started in a framework, stick with it.
- 10:23SPEAKER_02: Number two, if your team is more familiar with JavaScript, then yeah, I think the JavaScript framework is probably a better option.
- 10:31SPEAKER_02: This is one of those things where people often, again, think that when I say it depends, that's just about what code is right for what situation.
- 10:41SPEAKER_02: It's about your team as well.
- 10:43SPEAKER_02: It's about your environment, it's about your ecosystem.
- 10:47SPEAKER_02: Where you might say, hey, you know what?
- 10:49SPEAKER_02: We're okay in C sharp, but we're really good in JavaScript.
- 10:52SPEAKER_02: Well, then absolutely do JavaScript.
- 10:56SPEAKER_02: Do what you're best at.
- 10:59SPEAKER_02: So that could be a reason.
- 11:01SPEAKER_02: Now, you may have a team that's great in JavaScript.
- 11:04SPEAKER_02: You may have code already written, one of the frameworks, but you may say, Yeah, but the benefits of Blazor outweigh that.
- 11:11SPEAKER_02: That's that's fine too.
- 11:12SPEAKER_02: It does again depend on your situation, where you want to be long term, how much you want to invest now versus later, what you want to have for features now versus later, and so many other choices.
- 11:25SPEAKER_02: But there are reasons why you might stick with JavaScript.
- 11:30SPEAKER_02: Now, number three is maybe your back end is in C sharp, but you don't support that.
- 11:36SPEAKER_02: Your team doesn't support the back end, they just do the front end.
- 11:40SPEAKER_02: Well, then you're not really tied to or already using the C sharp tooling.
- 11:45SPEAKER_02: Maybe there's not any benefits to you to using C sharp, and you can have a much more level playing field deciding Blazor versus a JavaScript framework.
- 11:56SPEAKER_02: There's still a lot of benefits to using Blazor, but you have a bit more of a decision to make than just start with Blazor in that case.
- 12:07SPEAKER_02: So there are definitely reasons to still stick with or go to a JavaScript framework.
- 12:14SPEAKER_02: But at the same time, I think that Blazor has made a really good case for why long term, it's probably a better choice in most situations or a lot of situations to use Blazor for your C sharp front end when you have a C sharp backend.
- 12:32SPEAKER_02: Now finally, let's look at why I don't recommend MVC or Razer pages anymore.
- 12:38SPEAKER_02: These are still supported by Microsoft and they're still in the ASP.NET Core ecosystem, and you can still even intermix them with Blazor.
- 12:49SPEAKER_02: But why don't I recommend that new projects start in MVC or Razer pages anymore?
- 12:56SPEAKER_02: Well, number one, they're not as flexible.
- 12:59SPEAKER_02: You're locked into server-side rendering.
- 13:02SPEAKER_02: You're locked into the site being built on the server and then passed down to the client.
- 13:09SPEAKER_02: This is why a lot of C sharp back-end projects use Angular React or Vue for the front end.
- 13:15SPEAKER_02: They'll use MVC or API and then have that be the foundation that sends the data down to a rich client-side interactive project because there weren't good options for rich client-side interactivity until Blazor Server and Blazor WebAssembly.
- 13:34SPEAKER_02: But even then, there were some limitations that kind of held people back.
- 13:38SPEAKER_02: But now I don't see the benefit of doing that when we have such a rich ecosystem with Blazor.
- 13:46SPEAKER_02: So just being locked into just server-side for the life of your application doesn't feel like a good long-term choice for a business.
- 13:58SPEAKER_02: Number two, MVC is more of a holdover from the.NET framework.
- 14:04SPEAKER_02: It used to be we had just web forms.
- 14:07SPEAKER_02: This is early.NET framework stuff.
- 14:09SPEAKER_02: We had just web forms.
- 14:11SPEAKER_02: It was like WinForms, Windows Forms, but for the web.
- 14:15SPEAKER_02: It was a drag and drop, you know, reusable components, and people kind of liked it.
- 14:20SPEAKER_02: But that has, you know, that was one way of doing the web, but it wasn't a great testable uh framework for server-side code.
- 14:30SPEAKER_02: And so Microsoft created MVC in the.NET framework, and that was the only other web project type that we really had for building web applications with C sharp.
- 14:42SPEAKER_02: And so everyone seemed to flock to MVC.
- 14:47SPEAKER_02: Well, since.NET Core, which is now just.NET, we've had a lot more options.
- 14:54SPEAKER_02: And I had a course, I have a course that goes over the different ASP.NET Core options, like Razor Pages and MVC and API and Blazor Server and Blazor WebAssembly, which now has even changed.
- 15:07SPEAKER_02: But with those five options, I said, okay, when will you use each?
- 15:12SPEAKER_02: And MVC almost invariably comes out last.
- 15:16SPEAKER_02: Because yes, it was a great option when the only other option is web forms.
- 15:22SPEAKER_02: But now we have better choices.
- 15:24SPEAKER_02: And so it had already been sliding away from the number one choice for most projects.
- 15:30SPEAKER_02: And now with the this new Blazor option, I just don't see the need for it.
- 15:36SPEAKER_02: It's much more of a legacy framework.
- 15:40SPEAKER_02: Now it does mean that if you're starting out in software development and you're looking to get a job, you'll probably come across MVC more than you will Blazor.
- 15:50SPEAKER_02: And the reason why is because MVC has been out for years.
- 15:56SPEAKER_02: And it was at one time the old the best framework out there for C Sharp.
- 16:02SPEAKER_02: And so a lot of companies have invested in MVC.
- 16:05SPEAKER_02: And now once you do, you're kind of locked into that framework going forward.
- 16:10SPEAKER_02: Again, kind of pointing back to what we learned earlier, Blazor allows you to not lock in as much.
- 16:16SPEAKER_02: This is a long-term benefit that Blazor offers that we didn't have before.
- 16:21SPEAKER_02: Once you made a choice, whether it was Angular React View or MVC or Razer Pages, you kind of locked into one way of doing things.
- 16:30SPEAKER_02: Well, with ASP.NET Core, we kind of expand a little bit where you can add features from one of the other frameworks and you have a little less lock-in.
- 16:40SPEAKER_02: But now with Blaze, we have a lot less lock-in.
- 16:43SPEAKER_02: So if you're getting into the marketplace today, you probably should still learn MVC because the fact that there's a lot of systems that are older systems that are still using MVC.
- 16:55SPEAKER_02: They haven't upgraded to anything else because there's not an upgrade path to a different framework.
- 17:01SPEAKER_02: They can upgrade to.NET 8 and you can have modern C sharp development, but it's still MVC.
- 17:07SPEAKER_02: So it's still a framework to learn, but Blazor is going to grow rapidly.
- 17:12SPEAKER_02: It's already grown very rapidly with Blazor Server and Blazor WebAssembly.
- 17:17SPEAKER_02: Now this new offering, it's going to be a much wiser choice for a lot of situations.
- 17:23SPEAKER_02: It's going to grow a lot faster.
- 17:25SPEAKER_02: So MVC, it's kind of just a holdover anymore.
- 17:29SPEAKER_02: And three Razor pages do allow for a simpler site, but they don't allow for that future expansion.
- 17:36SPEAKER_02: So you can create a Razor page really quickly.
- 17:40SPEAKER_02: And you can just throw something up and have a single page application or anything else, just a Razer page that just says, okay, here's the server-side rendered stuff, go.
- 17:50SPEAKER_02: And have an about us page or whatever.
- 17:52SPEAKER_02: But it doesn't allow for future expansion with the idea of adding some rich client-side interactivity without bringing in JavaScript and doing a JavaScript framework or set of libraries to get things working.
- 18:08SPEAKER_02: So you're kind of, it's a little bit of a dead end.
- 18:11SPEAKER_02: It's not, but it's a little bit because it takes more work to break out of Razor Pages and get into something like Blazor down the road, as opposed to just doing Blazor from the start.
- 18:25SPEAKER_02: So yes, you could build a Razor Pages site and then upgrade it later to Blazor, but it feels like you're not really setting yourself up for a strong future if you do that.
- 18:38SPEAKER_02: So choosing Blazor isn't about making a specific choice.
- 18:43SPEAKER_02: It's about allowing your project to have the flexibility of choice for years to come.
- 18:49SPEAKER_02: Instead of forcing your app to conform to one specific way of doing things from now on, you can choose what is best now and adjust as the need of your application changes.
- 19:00SPEAKER_02: That's kind of the power of Blazor.
- 19:03SPEAKER_02: And that's why I think that Blazor should now, from now on, be the starting point of your decision where you say, okay, we're gonna assume that it's gonna be Blazor, but why might we choose something else?
- 19:19SPEAKER_02: As opposed to saying, you know, what, you know, what choice should you make?
- 19:23SPEAKER_02: I would say start with the assumption that Blazor is your best choice, and then figure out if there's a better choice.
- 19:30SPEAKER_02: But look at all those benefits of Blazor first and make sure that there's something even better than those benefits with a different option.
- 19:39SPEAKER_02: All right.
- 19:40SPEAKER_02: So again, for me, I'm gonna be choosing Blazor for almost every project going forward.
- 19:45SPEAKER_02: All right, thanks for listening, and as always, I am Tim Corey.
- 19:49SPEAKER_00: Thank you for joining us for this episode of Def Questions.
- 19:52SPEAKER_00: Tim is committed to making it easier for you to become a developer.
- 19:56SPEAKER_00: If you would like to help make more content like this possible, please like, subscribe, rate, and share Dev Questions.
- 20:03SPEAKER_00: You can also send your questions to questions at IamTimcorey.com.
- 20:08SPEAKER_00: Until next time, remember, you are too smart and your time too valuable to waste it making all the mistakes Tim did.
- 20:15SPEAKER_00: When you're ready to learn to think and code like a professional developer, head over to imtimcore.com and enroll in a course.