An example for DI instance lifetime in ASP.NET Core 6 MVC
前言
在 ASP.NET Core 6 的開發框架下, 相依性注入 (Dependency Injection) 是跟以往 ASP.NET MVC 5 有很大不同的其中一項技術.
本篇文章, 主要是模仿參考文件 [1] 的範例, 進行演練.
在經由演練之後, 對於 ASP.NET Core 6 MVC 內建的 DI Container 套件, 也多了一份認識.
An example for DI instance lifetime in ASP.NET Core 6 MVC
在 ASP.NET Core 6 的開發框架下, 相依性注入 (Dependency Injection) 是跟以往 ASP.NET MVC 5 有很大不同的其中一項技術.
本篇文章, 主要是模仿參考文件 [1] 的範例, 進行演練.
在經由演練之後, 對於 ASP.NET Core 6 MVC 內建的 DI Container 套件, 也多了一份認識.
長久以來,一直很想試一下CI/CD,最近看到了 參考文件[1..] 的影片後,決定開始動手;將整個練習的過程記錄下來,供日後參考之用。
茲區分以下主要步驟作說明:
(一) 建立 ASP.NET MVC 專案
(二) 加入至 Git 版控,並推送至 GitHub
(三) 建立 GitHub CI/CD pipeline
(四) 將 .yml 檔 "認可並推送",此時會啟動 GitHub Actions 的執行
(五) 檢視網頁
(六) 改一下網頁內容,認可及推送,確定可以引發 GitHub Actions
2022.12.25 補充:
(七) 記得清理相關的資源群組 Resource Group
2022.12.28 補充:
(八) 處理設定 Hosting Plan 時,無法選擇免費 F1 主機的問題
話說 ASP.NET Core 6 支援跨平台, 但平常都在進行 Windows 平台專案的開發, 對 Linux 並不是很熟悉, 故需實際驗證, 才知道會有那些坑要解決或避開.
個人只是剛接觸 ASP.NET Core 6, 本篇文章只是將個人還到的跨平台問題, 作一些初步的整理; 若有不正確之處, 還請多加指正.
可能個人學藝不精, 遇到了 5 個關卡, 最後一個關卡還沒有時間處理. 日後如有時間再行驗證.
在前一篇 行尾結束字元探討 PART 1 : Git, 針對 行尾結束字元(End of Line) 在 Git 上的一些議題, 作了一些討論.
本篇再針對 End of Line 在 Vs Code 上的一些議題, 作一些討論.
經過實測發現, 雖然前一篇提到出現 "warning: in the working copy of '.gitignore', LF will be replaced by CRLF the next time Git touches it" 的訊息, 其實對整個版控並無影響, 只是一個提醒而已; 但這整個過程, 將以前沒有注意到的細節, 作了一次探討; 也第一次在 Ubuntu 上安裝 ASP.NET Core 6.0 SDK 及 Visual Studio Code, 並在 Ubuntu 上進行程式修及版控, 也算是有收穫了.
最近在 study vs code + dotne CLI 的開發方式, 當然也括 git 的部份. 當手工下達 git add . 指令時, 會出現 LF will be replaced by CRLF the next time Git touches it 的警告訊息.
PS D:\22-Projects.Git\52-ASP.NET Core\MvcFriends> git add . warning: in the working copy of '.gitignore', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of '.vscode/launch.json', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of 'wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of 'wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of 'wwwroot/lib/bootstrap/dist/css/bootstrap-grid.rtl.css', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of 'wwwroot/lib/bootstrap/dist/css/bootstrap-grid.rtl.min.css', LF will be replaced by CRLF the next time Git touches it
最近剛好有一些空檔, 由 .NET Framework 4.x 跨入 .NET Core 的世界, 目前 .NET Core 最新的 LTS (長期支援版本) 為 .NET 6. 而最簡單的程式, 就是 Console 主控台程式.
因此, 本文將撰寫一支 Console 主控台程式, 利用 Entity Framework Core (以下簡稱 EF Core)的工具, 將資料庫的 Table 轉為 C# 的 class, 並由前述主控台程式, 對資料庫進行讀取.
以下茲分幾個章節, 進行說明.
相關程式 可由此下載.
廠商要將資料庫結構異動, 發行至客戶測試機. 但廠商及客戶開發人員, 均不能連接至資料庫進行結構異動, 必須由客戶 DBA 進行處理.
回想以前在寫資料庫版本管控的文章時, 印象中 Will 保哥有提到 .dacpac 可以處理該狀況, 故作了一下複習及實作.
相關的程式碼, 可 由此下載.