Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
Embracing the Ebb and Flow
colly
86
4.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
41
7.3k
A designer walks into a library…
pauljervisheath
206
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Unsuck your backbone
ammeep
671
58k
Optimizing for Happiness
mojombo
379
70k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Documentation Writing (for coders)
carmenintech
71
4.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Docker and Python
trallard
44
3.4k
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