Improving .NET Core MVC Apps Using Extension Points

.NET Core is a new platform that brings even greater extensibility to the already flexible MVC framework. This course will explore how to leverage those extension points, and customize components of MVC to meet the evolving needs of your projects.
Course info
Rating
(33)
Level
Intermediate
Updated
Aug 2, 2018
Duration
3h 41m
Table of contents
Course Overview
Getting the Most Out of MVC
Improving Views and Layouts
Controlling Application Flow with Filters
Enhancing Data Binding and Validation
Customizing Application Responses
Influencing the Action Method Selection Process
Changing MVC Conventions Using the App Model
Customizing the Middleware Pipeline
Description
Course info
Rating
(33)
Level
Intermediate
Updated
Aug 2, 2018
Duration
3h 41m
Description

As you grow comfortable building MVC apps with .NET Core, you’ll quickly want to go further. Instead of just using MVC, you’ll want to control and customize its features and conventions. In this course, Improving .NET Core MVC Apps Using Extension Points, you'll learn how to adapt the framework to your project requirements, rather than limiting your vision to work within its default constraints. First, you'll learn how to extend or build custom versions of components like Tag Helpers, View Components, Filters, and more. Next, you'll explore customizing how incoming data is handled, and how outgoing response data is generated. Finally, you'll discover how to modify the internal behaviors of MVC by customizing Action Method Selection, the Application Model, and the Middleware pipeline. By the end of this course, you’ll know how to extend or adapt MVC to the needs of your project, and take your skills to the next level.

About the author
About the author

Alex Wolf is passionate about software development and mastering new technologies. He has several years of experience working almost exclusively with the .NET Framework and related platforms. Alex is also a Microsoft Certified Professional in both MVC Application development and HTML 5 technologies. He loves learning new things!

More from the author
Code Analysis in Visual Studio 2019
Intermediate
1h 17m
Jun 6, 2019
Visual Studio 2019: Debugging
Beginner
1h 38m
Apr 30, 2019
More courses by Alex Wolf
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hey everyone. I'm Alex Wolf, and welcome to this course on how to improve your. NET Core MVC apps using extension points. Now,. NET Core is a new platform that brings even greater extensibility to an already flexible framework, so as you grow comfortable building MVC apps with. NET Core, you'll quickly want to go further. Instead of just using MVC, you'll want to control and customize its features and conventions. This course reveals how to adapt the framework to your project requirements instead of limiting your vision to work within its default constraints. So throughout this course, we'll learn how to build custom versions of components like Tag Helpers, view components, filters, and more. Together, we'll change the way request data is handled by extending the model binding and validation process. We'll also customize how response data is generated by the view engine and action results. Later in the course, we'll even see how to modify the internal behaviors of MVC by customizing action method selection, the application model, and the middleware pipeline. So by the end of this course, you'll know how to extend or adapt MVC to the needs of your project and take your skills to the next level. Now, before starting, you should have at least a general working knowledge of MVC. You should be comfortable with core concepts like controllers, action methods, and routing and be ready to learn more about how they work. If you've built a few simple but meaningful applications, you'll be ready to go. So I hope you'll join me on this journey to improve your applications using MVC extension points right here on Pluralsight.

Improving Views and Layouts
In this module, let's explore ways to improve our views and layouts. Although our app looks fairly nice on the surface, there are plenty of opportunities to improve the underlying code. So I have our app open on the home page here, and let's scroll down to the three informational widgets in the center. The marketing department would like to be able to easily reuse these items around the site. For example, maybe they want to place the Credit Card Rates on the Loan Application page or highlight individual CD rates around the site. However, although these items look like moveable widgets, as we'll see later, the actual code is tightly coupled to the home view. That is not ideal for our needs. Other opportunities for improvement can be found around the site. For instance, if we switch over to the Insurance page, you'll find this sort of title banner that we use on multiple pages. Right now, these banners are just sections of static HTML. Ideally, we would create some kind of reusable HTML element or widget that encapsulates this content with attributes for the title text and subtext. Another example on this page is our left nav over here. As we click through different items, you'll notice that they don't highlight the current page. It would be nice if these elements were smart enough to automatically assign active styling when their respective page is loaded. Now all of these enhancements are easily possible through the use of custom Tag Helpers and view components. These are new features in. NET Core that allow us to build smarter and more reusable UI elements. Let's start to look more closely at each of these tasks in the next clip, starting with Tag Helpers.

Customizing Application Responses
In this module, let's explore ways to customize how MVC generates responses for incoming requests. There are many potential components involved in this process, but we're going to focus mostly on view engines and action results. These are the extension points you'll probably utilize most often, so let's look at a few potential use cases for customizing them. Back on the home page, by now you should be familiar with these various HTML views and layouts that MVC sends to the browser. Well, what if we want to apply site-wide changes to some of these templates that can be turned on and off? So, for example, maybe the Marketing Department wants to test out new home page layouts, or if we switch over to our loan application process, maybe they want to try out different sidebars or flow indicators to increase completion rates. This ability to swap out views based on settings is commonly referred to as theming. Using the power of view engines, we'll see how to set up multiple possible themes with our app and enable them with config settings. Let's click over to the Resources page to see another example for customizing app responses. On this page, we have downloadable CSV files with information about financial plans and starter tables of rate data for people to work with. So, if I click to download one of these, we can open that up in Excel. Right now this is a simple demo template, but you can imagine more populated files in a real project. Well, these files are dynamically generated based on daily rate data, but the code to do so is a bit messy right now on the back end. We'll explore what's wrong with it later in the module and see how we can create custom action results to improve how data is sent back to the browser. In the next clip, let's start to discuss the details of some of the components we'll need to customize to make these enhancements.

Influencing the Action Method Selection Process
In this module, let's explore how we can influence which action method is selected to handle a request and why you might want to do so. Now, there are many potential scenarios for why you might want to customize action method selection. These components can answer questions like how do I enforce certain rules about the incoming URL structure or content, Or how can I have two action methods share the same URL, but are each triggered by other conditions like the HTTP verb type? Or maybe you're interested in versioning your API endpoints to provide support for legacy implementations. Well, in this module, we'll focus on a few example scenarios that are relevant to the Globomantics app, and will answer these types of questions for other projects. So, at a high level, we will focus on two stages of the request lifecycle where you can influence which action method will handle a request. The first is during routing when an incoming URL is matched to route templates. A component called a route constraint can enforce certain rules about the content or structure of those URL segments. The second extension opportunity is during action selection. Multiple action methods are often candidates to match a route, so we can leverage components called action constraints to decide on the best candidate. In the next clip, let's look at the first example of an application workflow we want to improve, starting with route constraints.