{"id":2211,"date":"2021-09-27T01:51:16","date_gmt":"2021-09-26T17:51:16","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=2211"},"modified":"2021-10-14T18:50:02","modified_gmt":"2021-10-14T10:50:02","slug":"request-pipeline-di-lifecycle","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2021\/09\/27\/request-pipeline-di-lifecycle\/","title":{"rendered":"D-18 \u751f\u547d\u9031\u671f ? request pipeline ? di lifecycle"},"content":{"rendered":"<h1>\u7db2\u9801\u7a0b\u5f0f\u7684\u57fa\u790e\u77e5\u8b58<\/h1>\n<p>\u6628\u5929\u5c0f\u5149\u5f9eK\u5927\u90a3\u908a\u5b78\u5230\u4e86\u5982\u4f55\u751f\u6210\u4e00\u500b\u7db2\u9801\u7a0b\u5f0f\u5c08\u6848\uff0c\u4e26\u4e14\u77ad\u89e3\u4e86\u7db2\u9801\u7a0b\u5f0f\u7684\u985e\u578b\uff0c\u9084\u6709\u7db2\u9801\u7a0b\u5f0f\u521d\u59cb\u7684\u8cc7\u6599\u593e\u7d50\u69cb\u548c\u521d\u59cb\u7684\u5169\u500b\u6a94\u6848\u7684\u5167\u5bb9\uff0c\u7136\u800c\u5728\u9032\u5165\u958b\u767c\u4e4b\u524d\u4eca\u5929\u8981\u5148\u4e86\u89e3\u4e00\u4e9b\u7db2\u9801\u7a0b\u5f0f\u7684\u57fa\u672c\u77e5\u8b58\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7db2\u9801\u7a0b\u5f0f\u7684\u57fa\u672c\u77e5\u8b58<\/h2>\n<p>\u300c\u65e2\u7136\u662f\u5b78\u7fd2\u7db2\u9801\u7a0b\u5f0f\u958b\u767c\uff0c\u9084\u662f\u8981\u5148\u5f9e\u57fa\u790e\u958b\u59cb\u3002\u300d<br \/>\n\u4e00\u5927\u65e9\u8001K\u5c31\u8ddf\u5c0f\u5149\u9019\u9ebc\u8aaa\uff0c\u9019\u6642\u5c0f\u5149\u6b63\u5750\u5230\u4f4d\u5b50\u4e0a\u9762\u9023\u96fb\u8166\u90fd\u9084\u6c92\u6253\u958b\uff0c\u800c\u5927\u982d\u4f9d\u820a\u5728\u9700\u6c42\u6587\u4ef6\u5f8c\u9762\u57cb\u982d\u82e6\u5e79\uff0c\u4e0d\u540c\u7684\u662f\u9700\u6c42\u6587\u4ef6\u5c11\u4e86\u4e00\u534a\u3002<br \/>\n\u300c\u524d\u8f29\u90a3\u6709\u4e9b\u751a\u9ebc\u57fa\u790e\u77e5\u8b58\u9700\u8981\u77e5\u9053\u7684\u55ce\u3002\u300d<br \/>\n\u5c0f\u5149\u807d\u5230\u8001K\u7684\u8a71\u4e4b\u5f8c\u7528\u5f88\u8a8d\u771f\u7684\u8868\u60c5\u5c0d\u8001K\u9019\u9ebc\u8aaa\u3002<br \/>\n\u300c\u8868\u60c5\u5f88\u597d\uff0c\u901a\u5e38\u7684\u5e74\u8f15\u4eba\u90fd\u53ea\u662f\u5b78\u4e00\u5b78\u600e\u9ebc\u5beb\u7a0b\u5f0f\uff0c\u90fd\u4e0d\u6703\u60f3\u5b78\u9019\u500b\u57fa\u672c\u529f&#8230;\u300d<br \/>\n\u9019\u6642\u5927\u982d\u62ac\u8d77\u982d\u4f86\u5077\u7b11\uff0c\u56e0\u70ba\u4ed6\u770b\u5230\u8001K\u5c0d\u8457\u5c0f\u5149\u958b\u59cb\u4e00\u9023\u4e32\u7684\u8aaa\u6559\uff0c\u4e0d\u904e\u6c92\u904e\u591a\u4e45\u4ed6\u9084\u662f\u8d95\u8457\u56de\u53bb\u8655\u7406\u81ea\u5df1\u7684\u9700\u6c42\u958b\u767c\u3002<br \/>\n\u300c\u597d\u7684\uff0c\u90a3\u6211\u5011\u4f86\u5148\u5b78\u5b78\u5169\u500b\u6771\u897f\uff0c\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\u8ddf\u76f8\u4f9d\u6ce8\u5165\u7684\u751f\u547d\u9031\u671f\u3002\u300d<br \/>\n\u5728\u8aaa\u5b8c\u4e00\u9577\u4e32\u7684\u8aaa\u6559\u5f8c\u7d42\u65bc\u8981\u958b\u59cb\u9032\u5165\u6b63\u984c\u3002<\/p>\n<h3>request pipeline<\/h3>\n<p>\u9996\u5148\u8981\u5148\u4ecb\u7d39dotnetcore\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\u8d70\u7684\u65b9\u5f0f\uff0c\u95dc\u65bc\u9019\u65b9\u9762\u8acb\u5927\u5bb6\u5148\u770b\u4e00\u4e0b\u4e0b\u5716\u3002<\/p>\n<p><a href=\"https:\/\/www.develop-note.com\/blog\/wp-content\/uploads\/2021\/09\/dotnetcore-request-pipeline.svg\"><img decoding=\"async\" src=\"https:\/\/www.develop-note.com\/blog\/wp-content\/uploads\/2021\/09\/dotnetcore-request-pipeline.svg\" alt=\"MSDN\u7684.Net Core Request Pipeline\" \/> MSDN\u7684.Net Core Request Pipeline<\/a><\/p>\n<p>\u9019\u662f\u4e00\u500b\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\uff0c\u7531\u8acb\u6c42\u767c\u52d5\u5f8c\u7d93\u904e<code>Routing<\/code>\u53ca<code>Middleware<\/code>\u7b49\u7b49\u7684\u8655\u7406\u5f8c\u518d\u9032\u5165\u5230<code>Endpoint<\/code>\u8655\u7406\u5f8c\u6703\u958b\u59cb\u56de\u5230<code>response<\/code>\u7684\u90e8\u5206\u3002\u81f3\u65bc<code>Endpoint<\/code>\u8acb\u770b\u4e0b\u5716\u3002<\/p>\n<p><a href=\"https:\/\/www.develop-note.com\/blog\/wp-content\/uploads\/2021\/09\/dotnetcore-mvc-endpoint.svg\"><img decoding=\"async\" src=\"https:\/\/www.develop-note.com\/blog\/wp-content\/uploads\/2021\/09\/dotnetcore-mvc-endpoint.svg\" alt=\"MSDN\u7684.Net Core Mvc Endpoint\" \/> MSDN\u7684.Net Core Mvc Endpoint<\/a><\/p>\n<p>\u4e0a\u5716\u5247\u662f\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\u4e2d<code>Endpoint<\/code>\u7684\u90e8\u5206\uff0c\u5176\u4e2dMVC\u4ee5\u4f8b\u5b50\u70ba\u4f8b\u53ef\u4ee5\u518d\u5206\u6210<code>Filter<\/code>\u7684\u8655\u7406\u4ee5\u53ca<code>Model Valiadtion<\/code>\u548c<code>Model Binding<\/code>\u7684\u904e\u7a0b\u5f8c\u6703\u9032\u5230Controler\u7684<code>Action<\/code>\u7684\u90e8\u5206\uff0c\u5176\u8655\u7406\u7d30\u7bc0\u90e8\u5206\u53ef\u4ee5\u53c3\u8003<a href=\"https:\/\/www.c-sharpcorner.com\/article\/asp-net-core-mvc-request-life-cycle\/\" title=\"MVC life cycle\" rel=\"nofollow noopener\" target=\"_blank\">MVC\u7684\u751f\u547d\u9031\u671f<\/a>\u3002<br \/>\n\u56e0\u6b64\u5728\u7a0b\u5f0f\u958b\u767c\u7684\u90e8\u5206\u53ef\u4ee5\u4f9d\u64da\u9700\u6c42\u628a\u90e8\u5206\u7684\u908f\u8f2f\u653e\u5230Filter\u5167\uff0c\u7136\u5f8c\u9a57\u8b49\u7684\u8655\u7406\u5f8c\u5728\u5230<code>Action<\/code>\u5167\u8655\u7406\u5546\u696d\u908f\u8f2f\u3002<br \/>\n\u6240\u4ee5\u95dc\u65bc\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\u5230\u6b64\u5148\u544a\u4e00\u6bb5\u843d\uff0c\u81f3\u65bc\u5167\u90e8\u7d30\u7bc0\u5230\u6642\u6703\u5728\u5f8c\u7e8c\u7ae0\u7bc0\u5728\u66f4\u9032\u4e00\u6b65\u8aaa\u660e\u8a72\u968e\u6bb5\u8655\u7406\u7684\u904e\u7a0b\u3002<\/p>\n<h3>di lifecycle<\/h3>\n<p>\u525b\u525b\u4ecb\u7d39\u5230Controler\u7684Action\u7684\u90e8\u5206\uff0c\u6240\u4ee5\u9019\u88e1\u4e5f\u5148\u8aaa\u660e\u4e00\u4e0b\u4e4b\u5f8c\u8981\u4ecb\u7d39\u7684<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/aspnet\/core\/fundamentals\/dependency-injection\" title=\".NET Core \u4e2d\u7684\u76f8\u4f9d\u6027\u63d2\u5165\" rel=\"nofollow noopener\" target=\"_blank\">\u76f8\u4f9d\u6027\u63d2\u5165<\/a>\u7684\u91cd\u8981\u89c0\u5ff5<code>di lifecycle<\/code>\uff0c\u4e0d\u904e\u9019\u908a\u4ecb\u7d39\u7684\u662fdotnetcore\u539f\u751f\u7684\u76f8\u4f9d\u6ce8\u5165\u7684\u5de5\u5177\u7684\u540d\u8a5e\uff0c\u4e4b\u5f8c\u4ecb\u7d39<code>autofac<\/code>\u6642\u6703\u4ecb\u7d39\u4e4b\u9593\u7684\u5c0d\u61c9\u3002<br \/>\n\u9019\u908a\u76f8\u4f9d\u6ce8\u5165\u7684\u751f\u547d\u9031\u671f\u985e\u5225\u5982\u4e0b:<\/p>\n<table>\n<thead>\n<tr>\n<th>\u751f\u547d\u9031\u671f\u985e\u5225<\/th>\n<th>\u8aaa\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Transient<\/td>\n<td>\u6bcf\u4e00\u500b\u5143\u4ef6\u7684\u5be6\u9ad4\u90fd\u662f\u4e0d\u540c\u7684\uff0c\u4f8b\u5982\u5728\u4e0d\u540c\u7684\u7269\u4ef6\u4e2d\u6ce8\u5165\u7684\u5143\u4ef6\u90fd\u662f\u4e0d\u540c\u7684<\/td>\n<\/tr>\n<tr>\n<td>Scoped<\/td>\n<td>\u540c\u4e00\u500b\u8acb\u6c42\u4e2d\u7684\u5143\u4ef6\u6703\u662f\u76f8\u540c\u7684\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u8acb\u6c42\u5247\u6703\u662f\u4e0d\u540c\u7684\u5143\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>Singleton<\/td>\n<td>\u6574\u500b\u7db2\u9801\u7ad9\u53f0\u4e2d\u7684\u5be6\u4f8b\u53ea\u6703\u6709\u4e00\u500b\uff0c\u5c31\u7b97\u662f\u4e0d\u540c\u7684\u8acb\u6c42\u6240\u6ce8\u5165\u7684\u5be6\u4f8b\u4e5f\u662f\u4e00\u6a23\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6703\u63d0\u5230\u9019\u500b\u90e8\u5206\u662f\u8981\u6ce8\u610f\u901a\u5e38\u7684\u985e\u578b\u90fd\u662f\u4f7f\u7528<code>Scoped<\/code>\u7684\u9019\u500b\u985e\u578b\uff0c\u4f46\u5982\u679c\u8981\u6ce8\u5165\u7684\u5143\u4ef6\u4f8b\u5982\u6703\u9700\u8981\u7dad\u6301\u4e00\u689d\u9023\u7dda\u7684\u72c0\u6cc1\u4e0b\u6703\u4f7f\u7528<code>Singleton<\/code>\u7684\u985e\u578b\uff0c\u81f3\u65bc\u5728\u662f\u7528<code>Transient<\/code>\u6642\u8981\u6ce8\u610f\u8a72\u5143\u4ef6\u4e0a\u662f\u5426\u6709\u72c0\u614b\u7684\u5b58\u5728\uff0c\u4f46\u662f\u4f7f\u7528Transient\u4e0a\u6703\u9020\u6210\u8cc7\u6e90\u7684\u6d6a\u8cbb\uff0c\u6240\u4ee5\u8a2d\u8a08\u4e0a\u6703\u4f7f\u7528<code>Scoped<\/code>\u4e26\u4e14\u6ce8\u610f\u4e0d\u8981\u6709\u8ddf\u8acb\u6c42\u72c0\u614b\u6709\u95dc\u7684\u8b8a\u6578\u5b58\u5728\u4e0a\u9762\u4f86\u53d6\u4ee3<code>Transient<\/code>\u3002<\/p>\n<h2>\u5f8c\u8a18<\/h2>\n<p>\u4eca\u5929\u8001K\u8ddf\u5c0f\u5149\u4ecb\u7d39dotnet core\u7684\u57fa\u672c\u529f\uff0c\u8acb\u6c42\u7684\u6d41\u6c34\u7dda\u8ddf\u76f8\u4f9d\u4f4f\u6ce8\u5165\u7684\u751f\u547d\u9031\u671f\uff0c\u5e0c\u671b\u80fd\u5920\u8b93\u8b80\u8005\u5011\u5c0d\u65bc\u7db2\u9801\u7a0b\u5f0f\u958b\u767c\u7684\u77e5\u8b58\u6709\u4e00\u4e9b\u8a8d\u8b58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7db2\u9801\u7a0b\u5f0f\u7684\u57fa\u790e\u77e5\u8b58 \u6628\u5929\u5c0f\u5149\u5f9eK\u5927\u90a3\u908a\u5b78\u5230\u4e86\u5982\u4f55\u751f\u6210\u4e00\u500b\u7db2\u9801\u7a0b\u5f0f\u5c08\u6848\uff0c\u4e26\u4e14\u77ad\u89e3\u4e86\u7db2\u9801\u7a0b\u5f0f\u7684\u985e\u578b\uff0c\u9084\u6709\u7db2\u9801\u7a0b\u5f0f\u521d &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2021\/09\/27\/request-pipeline-di-lifecycle\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008D-18 \u751f\u547d\u9031\u671f ? request pipeline ? di lifecycle\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[90,92,108,110],"class_list":["post-2211","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2021ironman","tag-dotnetcore","tag-lifecycle","tag-pipeline"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=2211"}],"version-history":[{"count":29,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2211\/revisions"}],"predecessor-version":[{"id":2629,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2211\/revisions\/2629"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=2211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=2211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=2211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}