.NET CORE 3.1 Web API For Beginners Part 02 — Reviewing the project files.



  • logo.jpg

    image is taken from www.syncfusion.com

    In the previous article, I explained the basics of .Net Core web API, How to create a project and run it using .Net CLI. You can read it here.

    Today as I promised, we gonna take a look at the project files that we have given out of the box and what responsible for getting us the result we saw in the previous article.

    Program.cs

    program.png

    “Program.cs” is the most important file. because it is the starting point of our application. It contains a method called Main. When we hit the “dotnet run” command in the CLI, it’s looking for the “Main ”method in the “Program.cs” class and executes it. In the “Main ”method, it’s calling another method called “CreateHostBuilder” which you can see below the Main method and this responsible for configuring the webserver which is “Kestral ” with some default configurations. The configurations are read from appSettings.json / appsettings.Development.json files and we also provide some additional configurations inside a class called “Startup”.

    “Kestral” is an open-source cross-platform web server for Asp.Net Core.

    appSettings.json / appsettings.Development.json

    appSettings.png

    We can give our application some configurations inside the “ appsettings.json” file or we can use “ appsettings.Development.json” for development mode.

    Startup.cs

    Startup.png

    In the Startup class, we can see a constructer with configurations injected into that. So that we can read configurations we defined in appsettings.json.

    There are another two methods called “ConfigureServices ”and “Configure”.
    The “ConfigureServices ” method is our dependency injection container. We can create and add our own services to this. I’ll explain what is dependency injection and how to write our own services and add those into our application via dependency injection in another article.

    “Configure” is the place where we add middleware. I’ll also explain the use of middleware with another article.

    Controllers

    controller.png

    There is a file called “WeatherForecastController.cs” in the controllers' folder. It is the default controller that comes with the .Net Core web API. What controllers does is, When we start our application it’s going to map all of our endpoints in our controllers so that our API knows where to send the request to.

    launchsettings.json

    launchsettings.png

    There is another JSON file called “launchsettings.json”. When we start the application it also takes a look inside this file for any options. We have our application URL, environment variables, etc.

    These are the main files you need to know. To understand these things I will guide you on how to create our own API endpoints and services in upcoming articles.

    find me on medium - https://dlbnprabath.medium.com/


  • Linux Help

    Awesome bro, keep it up.



  • @root Thanks bro.


  • Web Development

    Thanks bro



  • thanks bro