Tagged with asp.net
I'm working on an example to explore some more complex modeling in EF (for SQL and NoSQL) but that's not ready so I thought I'd use it as a bed for some Validation testing I'm doing. The result is some exploration of the FluentValidation project that I haven't had time to dig into until now.
Validation is an interesting exercise in ASP.NET (Core) and trying to get it correct is quite difficult. Ultimately in this day of SPAs and mobile apps, we need a solution that handles the client and the server. If you don't validate on the server it just doesn't matter.
FluentValidation is a replacment for the existing validation attributes (DataAnnotations) that you might already be using. The idea is to separate the validation from the classes. To be clear, this doesn't replace setting up your Entity Framework types with Fluent API this is about server-side validation only. Think of it as a clearer way to define rules for validation of your models or DTOs.
ASP.NET Core 3 seems to be taking a similar tact to version 1 as it is adding a lot of functionality and phasing it in with different previews. While a lot of the articles seem to be focusing on the non-ASP.NET features (e.g. WPF, WinForms, etc.), I thought it would be nice to let those of you who are ASP.NET devs know what is in Preview 6 just for you.
It feels a lot like the ASP.NET MVC/API side is being treated as mature and stable as there is are not a lot of surface changes. Microsoft does seem to be doubling down on Razor Pages and Blazor. It feels like they want .NET Core to be a good fit for different styles and backgrounds of developer. This release is no different.
Let's take a look at the details:
I know I am not going to make everyone happy with this post. I've been hoping to not have to make this post, but Entity Framework Core has finally added support for Lazy Loading, so it's time.
This problem is not new. Entity Framework (not Core) also has this problem. But it's far easier to accidentally do this in that version. Luckily, Entity Framework Core has made it harder to inadvertently turn it on. Let's see what's wrong with Lazy Loading in Web Apps.
Just to make sure were talking about the same things, I'll explain how Lazy Loading works.
Like other posts, I am going to list all the changes I found but there are likely more that I didn’t run into. Feel free to use the comment system to add more as you like!
Rename all the “1.0.0-rc2-final” references to just “1.0.0”
This day has been a long time coming but I want to congratulate the team at Microsoft for delivering the first version of ASP.NET Core! I’m very excited to start working with the bits on real projects.
If you haven’t had a chance to look at play with ASP.NET Core, it’s time! For the ASP.NET MVC and Web API users, the transition is pretty quick, but if you’re coming from ASP.NET Web Forms or another technology, there is a learning curve.
My sense of it is that this is a new platform, not a new development model. You are closer to the metal without having to give up the productivity of the ASP.NET you’ve always loved (and maybe hated a little). This is a mature, open source, cross platform, and fast ASP.NET. It’s a new day in Microsoft’s web platform and it’s time to be a part of it.
I had a great time today talking about ASP.NET 5 on a Pluralsight webinar. Over 1,000 people were able to attend. Thank you all for tuning in!
The webinar showed the very basics of what ASP.NET 5 is and why it exists. I had fun answering all the questions and wish we had time to answer more.
Here is the source code for the project we created so you can play with the basics. This version using ASP.NET 5 RC1 so if you’re viewing this later on, the bits may not work quite right.
UPDATED: Missed fixes.
It’s that time again. ASP.NET 5 has a new release and this one has a go-live license! As announced today, the RC1 is available and a new RC2 is coming in the future.
If you’re like me, you have a couple of Beta 8 apps that you’d like to get up to speed with the RC1. In this post I’ll share with you the changes that I’ve found that impacted me. This isn’t exhaustive. Lucky for us, Beta8 to RC1 seems like a small jump (unlike earlier posts).
The course was recently updated to use the ASP.NET Beta 8 bits. I am looking forward to the next update of ASP.NET and expect to continue to update the course all the way through the RTM.
If you haven’t used Bower before, it is a package manager for client-side projects (i.e. jQuery, Bootstrap, Angular, etc.). Visual Studio makes this easy in the new incarnation and this clip shows you how it works. This video is from the third module of the course.
I had the opportunity to do three talks and two of them went well (if you were at my Bootstrap talk, you know what I’m talking about). In any case, I wanted to share the slide and code with the attendees so here it is:
If you’ve been following along, you know by now that I’m investing my time into learning ASP.NET 5. Now that the ASP.NET team have released a new version, let me help you move your code to the new version.
The update this time includes some simple package changes but also some major API changes. I am sure I can’t cover them all here, but hopefully I’ll help you avoid the major ones.
Let’s walk through the changes I am doing when upgrading a project:
The more I work with ASP.NET 5, the more it looks and feels like the old ASP.NET stack except for the hosting. That’s a good thing in most cases, but writing the API that changes.
After dealing with WCF’s bastardized tried to add REST on top of the SOAP stack, I was elated to be introduced to ASP.NET’s Web API some years back. While it let me develop APIs while thinking about REST in more natural forms, it had the problem of being so separated from the MVC stack that many of the facilities had to be duplicated in both stacks. This cognitive dissonance caused many a developer headaches (same class name but in two different namespaces). When I realized that ASP.NET 5 would be merging the two ideas, I was elated…maybe prematurely.
I had planned on finishing these a long time ago, but working on my Pluralsight course about ASP.NET 5 distracted me. Sorry about that.
If you’ve been doing web development in .NET, you probably have at least a passing experience with ASP.NET’s MVC framework. At it’s core, it’s a common way to build and architect web applications. The new stack is built on the same metaphors from the older versions. If you’ve been using MVC before, you won’t be lost and some of the additions are welcome.
I’ll explain what I’m doing in a series of blog posts and link them all here as I write them. The plan is to write posts about:
Part 4: ASP.NET MVC 6 (This Post)
Part 6: Web Tooling with VS2015 (coming soon)
As I’ve been digging into building apps with ASP.NET 5, I’ve had to get used to some of the new metaphors. Some of these make sense (especially if you’ve used Node before), but some are brand new to me. One of these metaphors I ran into was the idea of Identity notifications.
The problem I was running into was one I thought many people would run into: using Identity (e.g. authentication/authorization) with REST APIs. Here is the scenario:
I was using Cookie Authentication (similar to old ASP.NET’s Forms Authentication) to log in users and to protect certain pages of the site to non-anonymous users. It’s simple to set up and works well.
I’m diligently working towards my new Pluralsight course and I am very excited about it. The new course is an end-to-end building of a web app using ASP.NET 5, MVC6, Entity Framework 7, Angular 1.4, and Bootstrap 3.x.
This course is a bit different than other courses I’ve done because we’re releasing it before the RTM of ASP.NET 5. Because of this, I wanted to let my students know what to expect.
The course will build a web app from an empty ASP.NET 5 project through to a deployed app. This mirrors my ASP.NET MVC5 course from a couple of years ago, but is written with the new stack. The course will build a whole new project as well. This time, you’ll be building a tool for trip planning called “The World”.
As many of you know, my recent course on Pluralsight dealt with Best Practices in ASP.NET: Entities, Validation and View Models. As I’ve worked with clients, there seem to be a non-ending list of ways to deal with data in ASP.NET.
One of the topics that I am passionate about as it relates to the course is how to manage the Model to Entity relationship. While being pragmatic is important, I still believe that there are many situations where you want a separate Model for a view (server or client-side) instead of just using the Entities that you’re storing data with.
The challenge here is how to do the mapping between the entities and models without having to churn out tons of boilerplate. Luckily, there are a number of solutions including AutoMapper.
For my upcoming course, I have a decent sized example that I’ll be teaching from. In the process of watching ASP.NET 5 go through the sprints, I have to upgrade the project at every step. I feel at some point I should be getting better at dealing with the sprints, but not yet ; )
Here is a short post that includes the different things I had to deal with in upgrading the project. It’s not just the ASP.NET 5 update, but also EF7 and a couple of small details.
First, I followed these instructions I found as an answer to an upgrade problem on SO. It got me close:
A few weeks back, I released a new course on Pluralsight. This new course talks through what I consider “Best Practices” (though there are no absolutes) for ASP.NET Entities, View Models, and Validation.
I was tremendously pleased to find it made it into the top ten courses for a few days. It seems to be resonating with some students and that makes me really happy. If you’re writing ASP.NET code, this course could make your job easier!
The course covers:
NOTE: This post has been updated for changes in Beta 7 and later.
Every web project needs some sort of data framework and ASP.NET 5 is no exception. Like it’s forbearers, ASP.NET 5 uses Entity Framework, but this version of the Entity Framework is different. It’s being re-engineered from the ground up just like the ASP.NET 5 stack.
In this, the third part of my ASP.NET 5 series, I’ll be talking about Entity Framework 7. While you can use older versions of EF or other storage mechanisms (NoSQL, Postgres, etc.), I think it’s an interesting exercise to see what the EF team is thinking in this evolving version of the framework.
In this second post in my six-part series on ASP.NET 5, we’ll take a look at how your ASP.NET 5 applications will be configured upon startup. The startup in this new version of ASP.NET 5 is very different, but hopefully is clearer and easier to debug. At least that’s my impression so far.
If you haven’t read the prior topics, it would probably be helpful to start with the earlier articles. You can see a list of the links to the articles below:
I’ve been working on a new web site wholly using the ASP.NET 5 (e.g. vNext, MVC6, etc.) for the past couple of weeks. This means using Visual Studio 2015 Preview and the new project types in ASP.NET 5.
The idea around the site is to be an example of an ASP.NET 5 site using MVC6, EF7, and Visual Studio 2015. It’s not perfect and ASP.NET 5 isn’t ready yet so I expect to continue to fix and remove hacks for quite a while, but it’s been fun to dig into a whole new stack while it’s still getting the kinks worked out. Here are some of my first impressions.
You can see the code as it progresses, I’m I’m not done yet, but I’m sharing the code I’m working on via GitHub here:
I am getting married and that means I get a bunch of development tasks to do for the wedding planning. I guess it’s my own fault, I did propose with an app.
One of the tasks I had to do was create a new page on my wedding site for the day of the wedding to include things like directions and parking. Pretty simple HTML stuff, but one thing I wanted to be sure of was to only show the page on the day of the wedding. This should be easy, but the time zone of the server has kicked my ass before.
The problem is that if I check for the date, the date might get shifted if the time is after midnight where the server is. Luckily the TimeZoneInfo class makes this pretty easy in C#. The trick is to first get the time zone you care about:
As a fan of the direction of ASP.NET, I’ve been an avid fan of Phil Haack’s for some time now. His clarity of communicating why the web should work definitely helped ASP.NET become the great framework it is today. He’s now doing the same thing at GitHub!
I get to finally use my bad joke about his last name on this week’s podcast. We also talk about his start, the move to Seattle to work at Microsoft and how to keep Californian’s out of Washington state.
The Hello World Podcast is where I get to talk with some of your favorite authors, developers and speakers about how they got started in software development.
You can listen to episode 23 here:
One of the things that I help companies with are code reviews. I love doing code reviews. It let’s me look at a large codebase with fresh eyes and help a company out with a set of recommendations for improving their process, teams and code.
The purpose of this new course is to show you some of the lessons that can be learned through code reviews. I’ve broken up the lessons into several parts:
It was fun plumbing the depths of how it works. I generally like the feature but the implementation may change some of your code if you’re dealing with routes under the covers (i.e. for auth or versioning).
If you want a quick overview, I really like Dan Wahlin’s walkthrough of the feature here:
In this new course I build a new web site from scratch. I start out with a Bootstrap template (since my design skills suck) and move through creating content, building a database, exposing a REST-ful API and building a Single Page Application. I wrap it up by publishing the site to Azure Web Sites showing you how to not only get your application up an running in the cloud, but also how to monitor it and handle standard tasks like using your own domain in Azure.
You will see every line of code (with one small exception) that I write. This isn't slide-ware…it's show-n-tell. I use a range of technologies including: