ASP.NET Core Quick Start Review

Kevin O'Shaughnessy
May 14, 2017 · 10 min read

Welcome to this review of http://aspnetcorequickstart.com/ by Steve Smith.

ASP.NET Core Quick Start is a Dev IQ course, making a change from my regular reviews of Pluralsight courses. The course sells for $49.99 and I will be comparing it to other online course offerings at the end of this review.

You don’t need to have any previous experience of ASP.NET Core, or even much programming experience at all, to learn this course as Steve takes you all the way from the beginning.

In December 2018 this course was updated to cover ASP.NET Core 2.0 and Razor Pages. In addition, it now includes a lab manual and eBook focused on helping you build and architect clean applications using ASP.NET Core.

It is beneficial, but not essential to have some very basic prior knowledge of web servers such as IIS.

I recommend learning the basics of the C# language and web programming before watching this course. You should understand common programming terms such as constructor, dependency, MVC, lambda, async and middleware. You will probably get some benefit from the course even if all of those terms are unfamiliar however.

It is mostly aimed at people who are new to ASP.NET Core but also contains more advanced content later on that is useful to intermediate and even highly experienced developers.

The Agenda for the course is:

  • ASP.NET Core Goals and Benefits
  • Installing ASP.NET Core
  • Creating ASP.NET Core Apps in Visual Studio and VS Code
  • ASP.NET Core Startup
  • Injecting Dependencies in ASP.NET Core
  • Real World Middleware
  • ASP.NET Core MVC and Web APIs
  • Testing ASP.NET Core Apps
  • Clean DDD Architecture for Non-Trivial ASP.NET Core Apps
  • Bonus Content

A feature that I find really important with online training is the ability to change the playback speed. Dev IQ allows you to choose between 1x, 1.25x, 1.5x, 1.75x or 2x. For this course I found 1.5x works well. Unfortunately it changes back to 1x again after each video clip, or other server side change. It’s a little annoying having to keep resetting this and I hope that Dev IQ change this to a cookie based solution soon.

The Goals and Benefits video clip begins with an explanation of ASP.NET 4.6 and ASP.NET Core 1.0. I recommend having a read of the latest news from Build 2017 on ASP.NET Core 2.0 conjunction with this.

Steve then explains the relationship with GitHub and many other benefits of this technology, including statistics on how fast it is.

Chapter 2 Installing (6 minutes)

Chapter 3 Creating Apps in VS and VS Code (9 minutes)

There’s a demo showing how to find your ways around a basic Web Application in Visual Studio 2017. Next we see the command line interface and some useful commands. Steve runs these commands from his Mac’s bash terminal. So by the end of this chapter you should know how to get started.

Chapter 4 Startup (17 minutes)

10 minutes in, Steve introduces the Startup class, which is useful for configuring how our app behaves. He describes the constructor, ConfigureServices and Configure methods, and then gives a demonstration explaining the default web application code.

Also see Steve’s article Hosting in ASP.NET Core.

Chapter 5 Middleware (26 minutes)

Steve likens middleware to nesting dolls, and we see a diagram showing how three pieces of middleware interact with each other in a nested fashion.

We see examples of some common functions for creating middleware:

  • app.Run
  • app.Use
  • app.Map

We see a demonstration of how to create custom middleware in Startup, beginning with how to chain together two pieces of middleware with app.Use. We see our app displays either “Hello, world!” or “Hello, students!” depending on the URL we enter.

You don’t really want a lot of middleware code inside of your Startup class and Steve shows an example with your middleware in its own class, and demonstrates how to do this in Visual Studio Code. Fifteen minutes into this chapter we see the behavior is the same but our code is now much cleaner.

But as Steve explains, for most apps we don’t need to write our own middleware because there are already a selection of middleware to choose from. Steve describes the following pieces of Diagnostics middleware:

  • UseDeveloperExceptionPage
  • UseDatabaseErrorPage
  • UseBrowserLink
  • UseExceptionHandler
  • UseStatusCodePages
  • UseWelcomePage
  • UseElmPage
  • UseElmCapture

Seventeen minutes in, we see a demo of all of these middleware.

Finally, these other middleware are introduced:

  • UseIdentity
  • UseStaticFiles
  • UseDefaultFiles
  • UseDirectoryBrowser
  • UseFileServer
  • UseRouter
  • UseMvc
  • UseRewriter
  • UseResponseCompression
  • UseResponseCaching

Chapter 6 Dependency Injection (27 minutes)

If you are a Pluralsight subscriber, Steve Smith has also produced a course on the SOLID principles of Object Oriented Design which includes a through tutorial on Dependency Injection and Dependency Inversion.

However, Steve also introduces the concepts here and even if it is all new to you, once you see the examples you’ll understand that Dependency is essentially a $20 dollar term for a 20 cent concept!

Steve explains the Explicit Dependencies Principle and how it is important for looser coupling, followed by the Dependency Inversion Principle.

These principles lead us to what is sometimes called “Poor mans dependency injection” — manually constructing many objects. Inversion of Control (IOC) containers make use of the Factory pattern to significantly reduce the amount of work you need to do.

Steve explains some of the IOC containers available with ASP.NET Core. We learn IServiceProvider and IServiceCollection here, as well as the Transient, Scoped and Singleton Service Lifetimes.

9 minutes in, we see a dependency injection demonstration using Visual Studio Code, and this moves onto the HomeController 14 minutes in. There is nothing very complicated with this technique, but it is very powerful and leads to much more maintainable and testable code.

The demonstration includes creating a TimeService and a MessageService and the effect of the different Service Lifetimes on the program behavior.

Finally, Steve gives some advice about Service Lifetimes with Entity Framework Core.

Chapter 7 — MVC and Web API (77 minutes)

It is almost a course in itself, lasting a whopping 77 minutes. This is a huge amount of information to absorb at once, so here’s an overview of what might be of interest to you:

Steve begins by explaining what MVC is, discusses Controllers and Actions, and Returning Data or Views. He talks about the difference between models and viewmodels, and then moves on to describe ASP.NET MVC data annotations such as [HttpGet] and [AllowAnonymous].

We see that it is just a simple one line of code to return any of the following views or objects:

  • default view
  • view with a viewmodel
  • a view with a specified name
  • an object formatted based on request
  • a JSON-formatted object
  • a 200 HTTP status
  • OK result with data
  • a 400 Bad request status

Steve then gives a demonstration in Visual Studio showing all the relevant Microsoft AspNetCore and EntityFrameworkCore dependencies.

We see examples of returning specified views, and a view with a viewmodel containing contact details (Name, BlogName, BlogUrl and Twitter).

Postman

We see some best practices such as using asynchronous tasks and using Generics.

It is extremely easy to perform basic validations on request inputs using data annotations such as [Require] and [MaxLength(30)] and we see appropriate responses returned and displayed in Postman.

Working with Views

34 minutes in Steve covers Routing to actions, and this hasn’t changed significantly from ASP.NET MVC 5. Steve gives a few tips for working with Routes painlessly, and then covers model binding and model binding attributes such as [BindRequired] and [BindNever].

Working with Data

Starting at 45:42, we see a demonstration of how to modify data. While choosing the project template, the “Individual User Accounts” authentication option provides SQL Server database support.

Microsoft gives us a starter app, but when we login in we see an error page with the message “A database operation failed while processing the request”. This is easy to fix — we just click the “Apply migrations” button and the rest is magic.

Actually it’s not really magic, as Steve shows us the database that has been created for us, and the tables that are in it. We see how to add and update migrations using the command line.

We build a TodoItemsController and see how to use async with Tasks. The basic code just returns an empty list, so then we write a method to add new todo items. We fire off our HTTP requests using Postman.

Later in the demo we receive the error:

InvalidOperationException: Unable to resolve service for type ‘ModifyingDataDemo.Interfaces.IToDoItemRepository’ while attempting to activate ‘ModifyingDataDemo.Controllers.ToDoItemController’.

Steve says this is a common error related to Dependency Injection, and we see how to fix this by adding a new service to the ConfigureServices method in our Startup.cs class.

Filters

An example of a useful built-in filter is the [ValidateAntiForgeryToken] which generates an error if forgery tokens do not match.

Steve shows us that we can greatly reduce the amount of code needed in our controller methods by moving logic out into[ValidateModel] and [ValidateAuthorExists] filters. Then we can reduce the lines of code even further by applying filters at the class level rather than the method level.

Chapter 8 Testing (32 minutes)

Even if you have never written a test before, you’ll learn everything you need to know to get started writing both unit and integration tests, and understand when it is most appropriate to write either of these types of automated tests.

We also learn about the new Visual Studio 2017 live unit testing feature which enables continuous running of our tests.

Steve recommends writing unit tests for your business logic, but recommends trying to keeping that code away from ASP.NET Core. Test logic in your controllers, but there should only be minimal logic there.

Unit tests for your controllers don’t test middleware routes, model binding or filters, so they might not be as valuable as you hoped they would be.

For much more comprehensive integration testing, we can use TestServer.

The demonstration starts 9 minutes in and we start with a new xUnit Test Project.

We write an integration test called ReturnsListOfAuthors. This fails with a FileNotFoundException because we are missing a mandatory appsettings.json file. We can fix this by adding this file to the project and specifying that it is copied to the output folder.

The test still fails because there isn’t yet any data available. We see how to write a PopulateTestData function that fixes this problem.

We also see how to test an MVC method that returns a view.

Chapter 9 Clean DDD architecture (15 minutes)

Steve explains the benefits of an N-Tier architecture.

A couple of criticisms of N-Tier architecture are that each tier is tight coupled to its adjacent ones, and every tier it dependent on the data source. Steve says dependencies on the tier below are known as transitive dependencies.

It is really useful to be able to test a single tier of a large application without being dependent on the database. So we revisit the dependency inversion principle introduced in Chapter 6.

Steve describes the ports and adapters architecture, which is generally considered to be superior to N-Tier architectures for large scale applications, and lists some clean DDD architecture principles that we make testing a lot quicker and easier.

Steve has written a Clean Architecture project and hosted it on Github. We see that it is composed of Core, Infrastructure and Web projects. Steve says in a big software development project he would separate the Test project into two: one for unit tests and one for integration tests.

Bonus Content

Lab Manual Architecting Modern Web Applications with ASP.NET Core 2.0 and Azure (eBook)

Comparison with courses on Pluralsight

Shawn Wildermuth’s Building a Web App with ASP.NET Core, MVC 6, EF Core, and Angular has been one of the most popular courses on Pluralsight for a long time now, but I haven’t watched much of it because 9 hours and 33 minutes is too big of a time investment for me.

I like that face that Steve Smith’s course keeps things very simple and sticks to just the stuff that you really need to know. It focuses on understanding the ASP.NET Core technology rather than getting bogged down with everything else needed to write professional applications.

After you’ve watched ASP.NET Core Quick Start you can decide for yourself whether or not you want to dive much deeper.

Pluralsight also has several several courses on Entity Framework by Julie Lerman that will complement the material covered in this course.

Kevin O'Shaughnessy

Written by

Sr. Full Stack Web Dev promoting better professional practices, tools, solutions & helping others. Blogger & aspiring 3D artist #followback.