Book Image

ASP.NET Core 5 for Beginners

By : Andreas Helland, Vincent Maverick Durano, Jeffrey Chilberto, Ed Price
Book Image

ASP.NET Core 5 for Beginners

By: Andreas Helland, Vincent Maverick Durano, Jeffrey Chilberto, Ed Price

Overview of this book

ASP.NET Core 5 for Beginners is a comprehensive introduction for those who are new to the framework. This condensed guide takes a practical and engaging approach to cover everything that you need to know to start using ASP.NET Core for building cloud-ready, modern web applications. The book starts with a brief introduction to the ASP.NET Core framework and highlights the new features in its latest release, ASP.NET Core 5. It then covers the improvements in cross-platform support, the view engines that will help you to understand web development, and the new frontend technologies available with Blazor for building interactive web UIs. As you advance, you’ll learn the fundamentals of the different frameworks and capabilities that ship with ASP.NET Core. You'll also get to grips with securing web apps with identity implementation, unit testing, and the latest in containers and cloud-native to deploy them to AWS and Microsoft Azure. Throughout the book, you’ll find clear and concise code samples that illustrate each concept along with the strategies and techniques that will help to develop scalable and robust web apps. By the end of this book, you’ll have learned how to leverage ASP.NET Core 5 to build and deploy dynamic websites and services in a variety of real-world scenarios.
Table of Contents (19 chapters)
1
Section 1 – Crawling
7
Section 2 – Walking
12
Section 3 – Running

Understanding dependency lifetimes

If you're completely new to ASP.NET Core, or haven't worked with ASP.NET Core for a long time, or if you're an experienced ASP.NET developer but don't really look into dependency lifetimes in detail, the chances are you might be using just one type of dependency lifetime to register all your services when building ASP.NET Core applications. This is because you are confused as to which service lifetime to use, and you wanted to play it safe. Well, that's understandable, because choosing which type of service lifetime to use can be confusing sometimes. Hopefully, this section will give you a better understanding of the different types of lifetimes that you can use within your application and decide when to use each option.

There are primarily three service lifetimes in ASP.NET Core DI:

  • Transient
  • Scoped
  • Singleton

Transient service

The AddTransient() method is probably what you were using most often...