diff --git "a/\351\253\230\344\277\212\346\235\260/2024.5.20.NET Core.md" "b/\351\253\230\344\277\212\346\235\260/2024.5.20.NET Core.md" new file mode 100644 index 0000000000000000000000000000000000000000..acc654fd9ba8ddd436ab7f5632865429f4004021 --- /dev/null +++ "b/\351\253\230\344\277\212\346\235\260/2024.5.20.NET Core.md" @@ -0,0 +1,41 @@ +| ### 1.什么是.NET Core? | | | +| ---------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [4](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_4) | .NET Core框架是免费、开源、跨平台的,可以运行在Linux、Macos、Windows平台下。 | +| | [5](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_5) | | +| | [6](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_6) | ### 2. .NET Core包含以下几部分内容: | +| | [7](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_7) | - CoreCLR | +| | [8](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_8) | - CoreFX | +| | [9](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_9) | - Roslyn变异器 | +| | [10](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_10) | - .NET Core CLI工具 | +| | [11](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_11) | | +| | [12](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_12) | | +| | [13](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_13) | ### 3. .NET Core的优点 | +| | [14](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_14) | - 支持独立部署,不相互影响; | +| | [15](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_15) | - 彻底模块化; | +| | [16](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_16) | - 没有历史包袱,运行效率高; | +| | [17](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_17) | - 不依赖于IIS; | +| | [18](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_18) | - 跨平台; | +| | [19](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_19) | - 符合现代开发理念:依赖注入、单元测试等。 | +| | [20](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_20) | | +| | [21](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_21) | ### 4.什么是ASP.NET Core? | +| | [22](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_22) | ASP.NET Core是免费、开源、高性能且跨平台的Web框架,用来构建Web应用程序。ASP.NET Core能够运行在多个操作系统平台上,包括Windows、macOS和Linux系统等。 | +| | [23](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_23) | | +| | [24](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_24) | ### 5.ASP.NET Core具有以下优点: | +| | [25](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_25) | - 跨平台,能够在Windows、macOS和Linux系统上开发、编译和运行。 | +| | [26](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_26) | - 统一Web UI与Web API开发 | +| | [27](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_27) | - 集成新式客户端框架和开发工作流 | +| | [28](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_28) | - 基于环境配置以及云就绪配置 | +| | [29](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_29) | - 内置依赖项注入 | +| | [30](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_30) | - 轻型的高性能模块化HTTP请求管道 | +| | [31](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_31) | - 能够在IIS、Nginx。Apache和Docker上进行托管或者在当前进程内自托管 | +| | [32](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_32) | - 当目标框架为.NET Core时,支持并行应用版本控制 | +| | [33](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_33) | - 简化新式Web开发工具 | +| | [34](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_34) | - 开源和以社区为中心 | +| | [35](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_35) | | +| | [36](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_36) | ### 6.ASP.NET Core主要特性 | +| | [37](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_37) | (1)跨平台与“自我宿主” | +| | [38](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_38) | (2)统一Web UI与Web API开发 | +| | [39](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_39) | (3)内置依赖项注入 | +| | [40](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_40) | (4)轻型的高性能模块化HTTP请求管道 | +| | [41](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_41) | (5)基于环境配置以及云就绪配置 | +| | [42](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#391b136f1b4e5b99a340041c13b27d85e63eae5a_0_42) | (6)支持容器 | \ No newline at end of file diff --git "a/\351\253\230\344\277\212\346\235\260/2024.5.21\345\210\233\345\273\272\350\247\243\345\206\263\346\226\271\346\241\210.md" "b/\351\253\230\344\277\212\346\235\260/2024.5.21\345\210\233\345\273\272\350\247\243\345\206\263\346\226\271\346\241\210.md" new file mode 100644 index 0000000000000000000000000000000000000000..8e070320dbcf6792c3cb50105a8aa4a92cf29d23 --- /dev/null +++ "b/\351\253\230\344\277\212\346\235\260/2024.5.21\345\210\233\345\273\272\350\247\243\345\206\263\346\226\271\346\241\210.md" @@ -0,0 +1,15 @@ +| ## 解决方案和项目之间的联系 | | | +| --------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [2](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_2) | 1.编译或者打包解决方案的时候,会同时编译或打包其下所有的项目 | +| | [3](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_3) | 2.如果运行解决方案的话,则会按照编排的(指定的启动项目),分别调整指定项目 | +| | [4](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_4) | | +| | [5](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_5) | ## 创建一个解决方案包含两个项目 | +| | [6](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_6) | dotnet new webapi -n Admin2024.Api | +| | [7](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_7) | | +| | [8](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_8) | dotnet new classlib -n Admin2024.Domain | +| | [9](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_9) | | +| | [10](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_10) | dotnet new sln -n Admin2024 | +| | [11](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_11) | | +| | [12](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_12) | dotnet sln add .\Admin2024.Api\ | +| | [13](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_13) | | +| | [14](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#b317a3bf8cca7e8bcc2daba4790000397f365b6e_0_14) | dotnet sln add .\Admin2024.Domain\ | \ No newline at end of file diff --git "a/\351\253\230\344\277\212\346\235\260/2024.5.23Startup\347\261\273.md" "b/\351\253\230\344\277\212\346\235\260/2024.5.23Startup\347\261\273.md" new file mode 100644 index 0000000000000000000000000000000000000000..647f67a6dc8f06eae3bf20d1b3f683ae0bd2b1d8 --- /dev/null +++ "b/\351\253\230\344\277\212\346\235\260/2024.5.23Startup\347\261\273.md" @@ -0,0 +1,103 @@ +| IWebHostBuilder接口有很多扩展方法,其中有一个很重要的是UseStartup方法,它主要向应用程序提供用于配置启动的类,而指定的这个类应具有以下两个方法。 | | | +| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [4](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_4) | | +| | [5](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_5) | - ConfigureServices:用于向ASP.NET Core的依赖注入容器添加服务 | +| | [6](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_6) | - Configure:用于添加中间件,配置请求管道 | +| | [7](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_7) | | +| | [8](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_8) | 这两个方法都会在运行时被调用,且在应用程序的整个生命周期内,只执行一次。其中ConfigureServices方法是可选的,而Configure方法则是必选的。在程序启动时,它会执行ConfigureServices方法(如果有),将指定的服务放入应用程序的依赖注入容器中,然后再执行Configure方法,向请求管道中添加中间件。 | +| | [9](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_9) | | +| | [10](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_10) | ## 今日作业 | +| | [11](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_11) | | +| | [12](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_12) | ```C# | +| | [13](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_13) | var builder = WebApplication.CreateBuilder(args); | +| | [14](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_14) | | +| | [15](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_15) | var app = builder.Build(); | +| | [16](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_16) | | +| | [17](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_17) | app.MapGet("/",async ctx => { | +| | [18](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_18) | | +| | [19](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_19) | await ctx.Response.WriteAsync("8888"); | +| | [20](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_20) | }); | +| | [21](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_21) | | +| | [22](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_22) | | +| | [23](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_23) | app.MapGet("/leaf",async ctx => { | +| | [24](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_24) | | +| | [25](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_25) | await ctx.Response.WriteAsync("9999"); | +| | [26](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_26) | }); | +| | [27](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_27) | | +| | [28](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_28) | app.Run(); | +| | [29](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_29) | | +| | [30](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_30) | | +| | [31](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_31) | ``` | +| | [32](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_32) | | +| | [33](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_33) | 1. 在最简单的形式下,转换为在单独的文件中写路径-抽离 | +| | [34](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_34) | | +| | [35](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_35) | | +| | [36](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_36) | | +| | [37](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_37) | 2. 在最简形式下,转换为原来传统的控制器的模式-转换 | +| | [38](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_38) | | +| | [39](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_39) | Controllers里: | +| | [40](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_40) | | +| | [41](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_41) | ``` | +| | [42](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_42) | using Microsoft.AspNetCore.Mvc; | +| | [43](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_43) | | +| | [44](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_44) | namespace HHH.Controllers{ | +| | [45](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_45) | | +| | [46](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_46) | [ApiController] | +| | [47](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_47) | [Route("[Controller]")] | +| | [48](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_48) | | +| | [49](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_49) | public class HomeController:Controller{ | +| | [50](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_50) | public IActionResult Index(){ | +| | [51](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_51) | return Ok("0123456"); | +| | [52](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_52) | } | +| | [53](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_53) | } | +| | [54](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_54) | | +| | [55](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_55) | } | +| | [56](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_56) | | +| | [57](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_57) | ``` | +| | [58](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_58) | | +| | [59](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_59) | | +| | [60](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_60) | | +| | [61](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_61) | Program.cs里: | +| | [62](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_62) | | +| | [63](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_63) | ``` | +| | [64](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_64) | | +| | [65](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_65) | var builder = WebApplication.CreateBuilder(args); | +| | [66](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_66) | | +| | [67](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_67) | // Add services to the container. | +| | [68](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_68) | | +| | [69](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_69) | builder.Services.AddControllers(); | +| | [70](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_70) | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | +| | [71](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_71) | builder.Services.AddEndpointsApiExplorer(); | +| | [72](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_72) | builder.Services.AddSwaggerGen(); | +| | [73](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_73) | builder.Services.AddControllers(); | +| | [74](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_74) | | +| | [75](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_75) | var app = builder.Build(); | +| | [76](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_76) | app.MapControllers(); | +| | [77](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_77) | | +| | [78](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_78) | // Configure the HTTP request pipeline. | +| | [79](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_79) | if (app.Environment.IsDevelopment()) | +| | [80](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_80) | { | +| | [81](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_81) | app.UseSwagger(); | +| | [82](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_82) | app.UseSwaggerUI(); | +| | [83](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_83) | } | +| | [84](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_84) | | +| | [85](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_85) | app.UseHttpsRedirection(); | +| | [86](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_86) | | +| | [87](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_87) | app.UseAuthorization(); | +| | [88](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_88) | | +| | [89](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_89) | app.MapControllers(); | +| | [90](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_90) | | +| | [91](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_91) | app.Run(); | +| | [92](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_92) | | +| | [93](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_93) | ``` | +| | [94](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_94) | | +| | [95](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_95) | ## ASP.NET Core中的依赖注入 | +| | [96](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_96) | | +| | [97](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_97) | ASP.NET Core框架内部集成了自身的依赖注入容器。 | +| | [98](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_98) | | +| | [99](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_99) | 优点:功能强大、简单,容易使用且效率更高 | +| | [100](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_100) | | +| | [101](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_101) | 在ASP.NET Core中,所有被放入依赖注入容器的类型或组件称为服务。容器中的服务有两种类型: | +| | [102](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_102) | | +| | [103](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_103) | - 框架服务 | +| | [104](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#ceb58e55caaa039104562e51f1bcd742fbdf92cf_0_104) | - 应用服务 | \ No newline at end of file diff --git "a/\351\253\230\344\277\212\346\235\260/2024.5.24.md" "b/\351\253\230\344\277\212\346\235\260/2024.5.24.md" new file mode 100644 index 0000000000000000000000000000000000000000..e1afaeb55b4e3a37247a2737463a2e55d3a7943e --- /dev/null +++ "b/\351\253\230\344\277\212\346\235\260/2024.5.24.md" @@ -0,0 +1,61 @@ +| 在Program.cs中写: | | | +| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [2](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_2) | | +| | [3](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_3) | ``` | +| | [4](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_4) | namespace mm.Api; | +| | [5](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_5) | | +| | [6](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_6) | public static class Program | +| | [7](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_7) | { | +| | [8](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_8) | public static void Main(string[] args) | +| | [9](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_9) | { | +| | [10](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_10) | CreateWebHostBuilder(args).Build().Run(); | +| | [11](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_11) | } | +| | [12](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_12) | public static IHostBuilder CreateWebHostBuilder(string[] args) | +| | [13](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_13) | { | +| | [14](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_14) | return Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(CreateWebHostBuilder=> | +| | [15](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_15) | { | +| | [16](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_16) | CreateWebHostBuilder.UseStartup(); | +| | [17](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_17) | }); | +| | [18](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_18) | } | +| | [19](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_19) | } | +| | [20](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_20) | ``` | +| | [21](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_21) | | +| | [22](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_22) | 在Startup.cs中写: | +| | [23](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_23) | | +| | [24](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_24) | ``` | +| | [25](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_25) | namespace mm.Api; | +| | [26](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_26) | | +| | [27](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_27) | public class Startup | +| | [28](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_28) | { | +| | [29](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_29) | // 注册或者添加中间件 | +| | [30](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_30) | public void Configure(IApplicationBuilder app) | +| | [31](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_31) | { | +| | [32](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_32) | app.UseRouting(); | +| | [33](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_33) | app.UseEndpoints(endpoints => | +| | [34](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_34) | { | +| | [35](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_35) | endpoints.MapControllers(); | +| | [36](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_36) | }); | +| | [37](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_37) | } | +| | [38](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_38) | // 准备用于依赖注入的服务 | +| | [39](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_39) | public void ConfigureServices(IServiceCollection services) | +| | [40](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_40) | { | +| | [41](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_41) | services.AddControllers(); | +| | [42](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_42) | } | +| | [43](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_43) | } | +| | [44](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_44) | ``` | +| | [45](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_45) | | +| | [46](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_46) | 在BooksController.cs中写: | +| | [47](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_47) | | +| | [48](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_48) | ``` | +| | [49](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_49) | using Microsoft.AspNetCore.Mvc; | +| | [50](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_50) | | +| | [51](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_51) | namespace mm.Api; | +| | [52](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_52) | [Route("[controller]")] | +| | [53](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_53) | public class BooksController:ControllerBase | +| | [54](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_54) | { | +| | [55](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_55) | public IActionResult Index() | +| | [56](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_56) | { | +| | [57](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_57) | return Ok("8888"); | +| | [58](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_58) | } | +| | [59](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_59) | } | +| | [60](https://gitee.com/level-22-net-class/webapi-class-notes/pulls/98/files#e83426d949eb45249f4a23fd0a9d26cc54a335d6_0_60) | ``` | \ No newline at end of file