選單
GSS 技術部落格
在這個園地裡我們將從技術、專案管理、客戶對談面和大家分享我們多年的經驗,希望大家不管是喜歡或是有意見,都可以回饋給我們,讓我們有機會和大家對話並一起成長!
若有任何問題請來信:gss_crm@gss.com.tw
1 分鐘閱讀時間 (158 個字)

[Dot Net Core](Graphic series ) 11. Explain at what stage the Assembly information of the Controller Class is added to the ApplicationPartManager Class when it is Resolved during the execution of EndPoint Middleware

netcorelogo

上一節我們證明 Singleton Service 被Resolve後,其記憶體是會被保留起來。

這節接續說明,當dot net core 執行 EndPoint Middleware時,要Resolve出 Controller Class 過程中,ApplicationPartManager 為何在被Resolve的時候就包含 Controller 的組件資訊?

回顧 Dot Net Core 運作概述,有一張圖敘述ApplicationPartManager: 

如上圖,當HostBuilder 在執行 Build 函式時,到第五大步驟CreateServiceProvide,會在Startup Class ConfigureServices 中呼叫AddMvcCore 函式,這個時間點會對ApplicationPartManager實體做處理,也就是會從 ServiceCollection的擴充函式GetApplicationPartManager 來取得ApplicationPartManager實體,以ServiceCollection. TryAddSingleton來註冊instance,並將Controller所在的Assembly Information 包裝到 ApplicationPart中,最後放到ApplicationPartManager. ApplicationParts集合中。 之後Dot Net Core 會執行 EndPoint Middleware,也會對ApplicationPartManager做Resolve,於"Comparison of Dot Net Core MVC and Asp.NET MVC-Timing of Controller Factory and Provider Decision"這節有敘述的圖:

如上,ControllerActionDescriptorProvider在建構子的參數物件被Resolve時,其ApplicationPartManager 也相同被DI機制Resolve出來。因為是Singleton的Service,所以記憶體都是被保留起來的,也就是ApplicationPartManager是在之前就已經註冊好的Singleton實體。之後透過裏頭已經有的組件資訊,將Controller與 Action 資訊萃取出來執行。

【叡揚資訊】2022年AI+Chatbot黑客松開跑 The Only Limitation is ...
[Dot Net Core](Graphic series )10. The easiest way...
 

評論

尚無評論
已經注冊了? 這裡登入
Guest
2024/04/26, 週五

Captcha 圖像