$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20220928-golang-meetup-di-fx_release_.pdf
Search
Ken Chen
September 28, 2022
0
390
20220928-golang-meetup-di-fx_release_.pdf
Ken Chen
September 28, 2022
Tweet
Share
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.3k
Code Reviewing Like a Champion
maltzj
527
40k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Producing Creativity
orderedlist
PRO
348
40k
Embracing the Ebb and Flow
colly
88
4.9k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
85
Marketing to machines
jonoalderson
1
4.3k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
6.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
370
[SF Ruby Conf 2025] Rails X
palkan
0
550
Transcript
用 Fx 來替 Go 依賴注入吧 Ken Chen @ Golang Taiwan
Gathering #64 2022/9/29
## About Me - OneDegree Backend Engineer - Go Developer
- Modern Software Engineering - Cinema, Modern Literature / Sociology
## 讓我們看看今天的話題 - 依賴注入 - 作為應用框架的 Fx - Fx 的實現
- 使用上要注意的點
依賴注入的目的
## 相依性的來源 - Repo 創建物件後,交給 Us 使用 - 那能不能要更多東西? Usecase
Repository
Usecase Repository Database Schema ## 相依性的來源 - Repo 的物件會影響到程式邏輯 -
資料庫的 Schema 會影響到程式邏輯
None
## 切分子系統 - 每一層中間加上介面 - 實作優先轉為介面優先 Usecase Repository <<Interface>> Repository
None
講這麼多,要怎麼做
None
None
None
None
好像很簡單? 那是因為沒放入應用
None
Usecase A Usecase B Repository A Postgres Repository C Repository
B MongoDB Redis
Fx 是依賴注入的應用框架
None
None
None
None
今晚我想來點 Graceful Shutdown
None
None
None
有沒有可能預配置?
Instance A NewFunc B invoke Invoke Provide Supply
None
想要解構賦值的話呢?
None
None
覺得參數太多怎麼辦?
None
想要打包成模組的話呢?
NewFunc B Module Provide NewFunc A Instance A Supply
None
None
需要多個相同型別的實例
None
None
None
None
Fx 是如何打造的?
None
None
None
None
None
關於 Fx 使用上的反思
None
None
## 可能的處理方式 - 加入自定義的 logger - 初始化階段,失敗直接 panic - 建立公司內的工具包,降低導入成本
- 評估使用 Fx 對加速的幫助
謝謝大家 medium