Luna Tech

Tutorials For Dummies.

ASP.NET Hosting Models

2021-11-21


Hosting

The process of deploying/installing an application into the server is called “Hosting”. Whenever you create an ASP.NET Core application, by default it contains an internal server provided by a .NET Core that is called Kestrel. Due to this server, we can run ASP.NET Core apps on any platform like Windows, Mac or Linux.

The new Program.cs file

builder.Services.xxx can add Services into the Dependency Injection container.

The app part was in the Startup.cs file, used to check environment, use static files, configure the routing..

Top-level statement

https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements

Top-level statements enable you to avoid the extra ceremony required by placing your program’s entry point in a static method in a class. The C# templates for .NET 6 use top level statements.

This new feature enables us to have a simpler Program.cs file for ASP.NET Core web applications!

Global Using

.NET 6 SDK has added a set of implicit global using directives which include the most common namespaces for the project type, so we don’t need to writing a lot of using statements.

For additional global using, we can create a separate file to put all the global using there, so our project look much cleaner.

Once you have a global using, the local using will be greyed out to indicate you don’t need that line of code.


OutOfProcess Hosting Model


InProcess Hosting Model - default

There are trade-offs between each of the hosting models. By default, the in-process hosting model is used due to better performance and diagnostics.