The easiest way to learn ASP.NET Core

ASP.NET Core is the main web application development framework in .NET, which is the core software development platform of the Microsoft stack. It comes with various application templates that would allow developers to build any kind of web application. For example, a simple REST API interface can be built by using the Web API project template, while a complete web application with the user interface can be built by using either Razor Pages or Model-View-Controller (MVC) template.

There are many benefits of learning ASP.NET Core. The framework is used by many large enterprises, so there are plenty of software developer vacancies that list this technology. It’s popular among top software companies, such as Checkout.com and Just-Eat, so, as a developer, you will have no shortage of lucrative opportunities once you know it.

I am primarily a Microsoft stack developer and ASP.NET Core is the main software development framework I use. I have also been doing professional mentorship of software developers for a while and the most common request that I’ve received was to help the mentee to learn ASP.NET Core from scratch. After helping multiple developers to achieve this goal, I have developed a very efficient system that allows people to learn all key aspects of ASP.NET Core in the quickest way possible. This is what we will talk about in this article.

The philosophy behind this system

After spending years creating educational content and mentoring software developers, I know that the most effective way to learn a programming concept is to practice it. This is the idea that this system is based on.

I will not give you theoretical knowledge of how ASP.NET Core works. There are plenty of sources online that cover all of this already. Even the official Microsoft documentation is mostly top-notch. I will provide links to some of these sources.

What I will do is provide multiple practical exercises for you to complete. Each exercise is designed to teach you a specific set of ASP.NET Core concepts by practicing them. It goes without saying that completing these exercises won’t make you an ASP.NET Core expert and it will teach you everything there is to know about ASP.NET Core. But it will give you sufficient knowledge to understand the key fundamentals, so you should become capable of working with ASP.NET Core projects in a real commercial environment. It will provide you with a strong foundation you can build upon.

To reiterate, the challenges described here won’t provide a detailed description of all the steps you will need to go through to complete them. That’s by design. Although some links to various pieces of documentation are provided, you will have to do your own research. This is to mimic the process of solving actual programming challenges in a real commercial software development environment.

Prerequisites

To work with ASP.NET Core, you need the following:

Also, this set of challenges will not be suitable for complete beginners. You should know some programming basics before embarking upon these challenges. However, you don’t necessarily need to have any prior knowledge of ASP.NET Core or any of its languages, such as C#.

Simple challenges that will help you to learn ASP.NET Core

These challenges are meant to be followed in sequence from the most basic to the most complicated. Once you complete them all, you should be comfortable with all main ASP.NET Core application types.

Challenge 1: Turning a plain ASP.NET Core project into a Web API project

Using either a code editor or a command line interface, create two ASP.NET Core projects. One project should be based on the Empty template that contains only the most basic ASP.NET Core components. The other project should be based on the Web API project template.

Your goal will be to compare the structure of the project side-by-side and apply the necessary changes to transform the project based on the Empty template into a Web API project. You can use the documentation on ASP.NET Core startup as guidance to understand what the differences are.

The purpose of this challenge

This challenge would help you to understand the basic structure of the ASP.NET Core application.

Challenge 2: Creating a TODO REST API application

Using the Web API project template, build an application that can manage a TODO list. The endpoints of the application should allow you to perform the following:

  • GET endpoint to list all items in the TODO list.
  • GET endpoint to return details of an individual item in the TODO list based on its unique identifier.
  • POST endpoint to insert a new item into the TODO list.
  • PUT endpoint to modify an existing item in the TODO list.
  • DELETE endpoint to remove an item from the TODO list.

We should be able to send requests to any of these endpoints from the browser by using the Swagger UI. The solution should use API controllers and follow the best practices of the RESTful architecture. At this stage, we would store the data in an in-memory dictionary inside a separate singleton class. This would help you to practice the thin controller principle and implement ASP.NET Core dependency injection.

The class containing the data needs to implement an interface. The interface needs to be injected into the constructor of the API controller class. The built-in dependency injection mechanism needs to register the mapping between the class and the interface. The reason for injecting the interface instead of directly using a concrete class is explained in this article about the dependency inversion principle.

The purpose of this challenge

The challenge would help you to understand how to build a REST API application that is commonly used in the software development industry. As well as teaching you the technical fundamentals of the Web API project, it will teach you the standards and best practices of building such an application.

Challenge 3: Adding Entity Framework and a database

The application would look the same as in the previous challenge, but you will now store the data in a database. There will no longer be any in-memory data structure that stores the TODO items. The data will now be stored in a SQL-based database. We need to add Entity Framework dependencies and implement the code-first approach to enable it.

The purpose of the challenge

Entity Framework and other object-relational mappers (ORMs) are commonly used in web applications alongside SQL databases. This challenge will help you to learn how to use them.

Challenge 4: Moving ORM dependencies to a separate class library project

Refactor the application so the ORM (Entity Framework) components are managed by a class library rather than the main application. This will set you up for further steps and enable you to reuse the ORM components in other application types.

The purpose of this challenge

Real applications rarely consist of just a single project. Typically, they are modular. A standard ASP.NET Core application template would be the entry point into the application. The rest of the functionality would be managed by class libraries. This challenge will help you to learn how to build a modular ASP.NET Core app.

Challenge 5: Creating an MVC TODO application

We will now create an ASP.NET Core application based on the MVC template. The functionality of the application would be the same as before. It will manage a TODO list stored in the database that we previously created. But this time, we will do so via an in-browser user interface.

We should have a separate view for every action. For example, there can be a view that lists all TODO tasks, a separate view to edit a task, etc. If you use Visual Studio on Windows, you can use the built-in scaffolding process to automatically create all the views. We should connect it to the same database as before by adding a reference to the class library project we created earlier.

The purpose of this challenge

This challenge will teach you how to work with ASP.NET Core MVC project templates. This would be useful to know because this project template is fairly popular in enterprise-grade applications.

Challenge 6: Adding authentication and authorization

Next, we will need to do the authentication and authorization to our MVC application. You can use the official documentation for the instruction on how to do so. The requirements are as follows:

  • Any anonymous user should be able to see the list of TODO items.
  • Only authenticated users should be able to view the details of each item.
  • Only the users with the admin role should be able to add, edit, or delete items from the list.

The purpose of this challenge

Authentication and authorization are integral parts of any enterprise-grade web application. This challenge will help you to get familiar with the concepts and learn the fundamentals of how to apply them in an ASP.NET Core application.

Wrapping up

These challenges are simple, but they are not necessarily easy. If you don’t have prior experience working with ASP.NET Core, each of these challenges may take you days, or even weeks to complete. So don’t worry if any of these is taking you a while.

There are some ASP.NET Core concepts and project templates that weren’t included. For example, we haven’t covered Razor Pages and gRPC Services. This is because this system focuses on fundamentals. Once you master the fundamentals, picking up any other concepts from ASP.NET Core becomes relatively easy.

If you want to learn any of the other concepts not covered here, you can create a challenge for yourself similar to the ones presented in this article. For example, if you want to learn how to use Razor Pages, you can build a TODO app similar to what we have built here but use the Razor Pages project template instead of MVC. If you want to learn how to use gRPC, you can create a gRPC service connected to the database and a separate gRPC client app that retrieves the data from it.

If you found this content useful, you may also like some of the technical books that I wrote or online courses that I created. You can also book me as your personal mentor while I still have spaces available. Hiring a mentor from the industry is proven to be the quickest way to boost your career.


P.S. If you want me to help you improve your software development skills, you can check out my courses and my books. You can also book me for one-on-one mentorship.