eShopOnAzure 项目教程
1. 项目的目录结构及介绍
eShopOnAzure 项目的目录结构如下:
eShopOnAzure/
├── .github/
├── src/
│ ├── Catalog.API/
│ ├── Identity.API/
│ ├── Marketing.API/
│ ├── Ordering.API/
│ ├── Payment.API/
│ ├── Shipping.API/
│ ├── Web.Blazor/
│ ├── Web.MVC/
│ └── Web.Spa/
├── tests/
├── .gitignore
├── LICENSE
├── README.md
└── global.json
目录结构介绍
- .github/: 包含 GitHub 相关的配置文件,如 GitHub Actions 的工作流配置。
- src/: 包含项目的源代码,分为多个 API 和 Web 应用程序。
- Catalog.API/: 商品目录服务的 API 项目。
- Identity.API/: 身份验证和授权服务的 API 项目。
- Marketing.API/: 营销服务的 API 项目。
- Ordering.API/: 订单服务的 API 项目。
- Payment.API/: 支付服务的 API 项目。
- Shipping.API/: 物流服务的 API 项目。
- Web.Blazor/: 使用 Blazor 技术构建的 Web 应用程序。
- Web.MVC/: 使用 MVC 技术构建的 Web 应用程序。
- Web.Spa/: 使用单页应用(SPA)技术构建的 Web 应用程序。
- tests/: 包含项目的测试代码。
- .gitignore: Git 忽略文件配置。
- LICENSE: 项目的开源许可证文件。
- README.md: 项目的介绍和使用说明。
- global.json: 项目的全局配置文件,通常用于指定 .NET SDK 版本。
2. 项目的启动文件介绍
在 eShopOnAzure 项目中,每个 API 和 Web 应用程序都有自己的启动文件。以下是一些主要的启动文件:
Catalog.API/Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Catalog.API
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Web.MVC/Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Web.MVC
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
启动文件介绍
- Program.cs: 每个项目的启动文件,负责创建和配置主机(Host),并启动应用程序。
- CreateHostBuilder: 创建主机构建器,配置 Web 主机默认设置,并指定
Startup
类作为应用程序的启动类。
3. 项目的配置文件介绍
eShopOnAzure 项目中包含多个配置文件,用于配置应用程序的行为和环境。以下是一些主要的配置文件:
global.json
{
"sdk": {
"version": "5.0.100"
}
}
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
配置文件介绍
- global.json: 指定项目使用的 .NET SDK 版本。
- appsettings.json: 包含应用程序的配置设置,如日志级别和允许的主机。
通过以上内容,您可以了解 eShopOnAzure 项目的目录结构、启动文件和配置文件的基本信息。