How it works

The Startup.cs file contains the Startup class. ASP.NET Core requires a Startup class and will look for this class by default. By convention the Startup class is called Startup, but you can call it something else if you want. If you need to rename it, then you also need to ensure that the Program.cs file is modified so that the WebHostBuilder() specifies the correct class name for .UseStartup:

public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}

Going back to our Startup class in the Startup.cs file, when you look inside this class you will see two methods. The methods are Configure() and ConfigureServices(). As you can see from the comment on the Configure() method, it is used to configure the HTTP request pipeline. Basically, incoming requests are handled by the application here and all it currently does in our application is to display the current date for every incoming request. The ConfigureServices() method is called before Configure() and is optional. Its explicit purpose is to add any services required by the application. ASP.NET Core supports dependency Injection natively. This means that if I can leverage services by injecting them into methods in the Startup class. For more information on DI, be sure to read https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.71.115