Preparing the basic project structure

You will surely want to see something running after building the Tic-Tac-Toe game application. Now that we have defined how everything should work from a functional point of view, we need to start by creating the basic project structure for the application.

For ASP.NET Core 3 web applications, it is best practice to have the following structure for your projects:

  • A Controllers folder, containing all of the controllers of your application.
  • A Services folder, containing all the services of your application (for example, external communication services).
  • A Views folder, containing all the views of your application. This folder should contain a single Shared subfolder as well as one folder per controller.
  • A _ViewImports.cshtml file, to define some namespaces to be available in all views.
  • A _ViewStart.cshtml file, to define some code to be executed at the start of each view rendering (for example, setting the layout page for all views).
  • A _Layout.cshtml file, to define a common layout for all of your views.

Let's create the project structure:

  1. Start Visual Studio 2019, open the Tic-Tac-Toe ASP.NET Core 3 project you have created, create three new folders called Controllers, Services, and Views, and then create a subfolder called Shared in the Views folder:

  1. Create a new view page called _ViewImports.cshtml in the Views folder:
        @using TicTacToe 
        @addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers 
  1. Create a new view page called _ViewStart.cshtml in the Views folder:
        @{ Layout = "~/Views/Shared/_Layout.cshtml"; }
  1. Right-click on the Views/Shared folder, select Add | New Item, enter Layout in the search box, select MVC View Layout Page, and then click on Add:

Note that the layout page concept will be detailed a little bit later in this chapter, but don't worry too much; it is not a very complicated concept.
..................Content has been hidden....................

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