The ConfigureServices method

Services are configured using a method called ConfigureServices. It is this method we will use to register items such as the following:

  • Our authentication user model and password policy
  • Our authorization policies
  • Whether we want to use MVC to handle requests
  • Whether we want to enable CORS
  • Our own classes that need to be available in dependency injection

Services are added by calling methods on the services parameter and, generally, start with Add. Notice the call to the AddSpaStaticFiles method in the following code snippet:

public void ConfigureServices(IServiceCollection services)
{0
services.AddControllersWithViews();

services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/build";
});
}

This is a key part of how the React app is integrated into ASP.NET Core in production because this specifies the location of the React app.

It is important to understand that the ASP.NET Core app runs on the server, with the React app running on the client in the browser. The ASP.NET Core app simply serves the files in the ClientApp/Build folder without any interpretation or manipulation.

The ClientApp/Build files are only used in production mode, though. Next, we'll find out how the React app is integrated into ASP.NET Core in development mode next.

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

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