Book Image

C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

By : Mark J. Price
5 (1)
Book Image

C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

5 (1)
By: Mark J. Price

Overview of this book

Extensively revised to accommodate all the latest features that come with C# 10 and .NET 6, this latest edition of our comprehensive guide will get you coding in C# with confidence. You’ll learn object-oriented programming, writing, testing, and debugging functions, implementing interfaces, and inheriting classes. The book covers the .NET APIs for performing tasks like managing and querying data, monitoring and improving performance, and working with the filesystem, async streams, and serialization. You’ll build and deploy cross-platform apps, such as websites and services using ASP.NET Core. Instead of distracting you with unnecessary application code, the first twelve chapters will teach you about C# language constructs and many of the .NET libraries through simple console applications. In later chapters, having mastered the basics, you’ll then build practical applications and services using ASP.NET Core, the Model-View-Controller (MVC) pattern, and Blazor.
Table of Contents (20 chapters)
19
Index

Exploring an ASP.NET Core MVC website

Let's walk through the parts that make up a modern ASP.NET Core MVC website.

Understanding ASP.NET Core MVC initialization

Appropriately enough, we will start by exploring the MVC website's default initialization and configuration:

  1. Open the Program.cs file and note that it uses the top-level program feature (so there is a hidden Program class with a Main method). This file can be considered to be divided into four important sections from top to bottom.

    .NET 5 and earlier ASP.NET Core project templates used a Startup class to separate these parts into separate methods but with .NET 6, Microsoft encourages putting everything in a single Program.cs file.

  2. The first section imports some namespaces, as shown in the following code:
    using Microsoft.AspNetCore.Identity; // IdentityUser
    using Microsoft.EntityFrameworkCore; // UseSqlServer, UseSqlite
    using Northwind.Mvc.Data; // ApplicationDbContext...