Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency injection #8458

Closed
syuilo opened this issue Apr 1, 2022 · 21 comments · Fixed by #9085
Closed

Dependency injection #8458

syuilo opened this issue Apr 1, 2022 · 21 comments · Fixed by #9085
Labels
🛠️Dev Development of Misskey itself 🔥high priority 💚Refactor Rewriting code without changing behavior

Comments

@syuilo
Copy link
Member

syuilo commented Apr 1, 2022

Summary

外部へのHTTPリクエストとかジョブキューの状態とか気にしないでテスト書けるようにしたい

InversifyJSとかのDIライブラリ使う or NestJSで書き直す

@syuilo syuilo added 🛠️Dev Development of Misskey itself 💚Refactor Rewriting code without changing behavior labels Apr 1, 2022
@syuilo
Copy link
Member Author

syuilo commented Apr 1, 2022

理想的には全部Nestで書き直すのが良いんだろうけど、私のスキルが足りなすぎるのとあまりにも大変になるから、現実的には必要な箇所だけDIコンテナライブラリ使ってやっていく感じになりそう

@syuilo
Copy link
Member Author

syuilo commented Apr 2, 2022

https://github.com/typestack/typedi がシンプルで良さそう

@syuilo
Copy link
Member Author

syuilo commented Apr 2, 2022

外部ライブラリのクラスのインスタンスとかはどうやって注入するんだろう

@syuilo
Copy link
Member Author

syuilo commented Jun 5, 2022

テスト上でTypeORMのRepositoryもDIしたい感じが出てきた

@syuilo
Copy link
Member Author

syuilo commented Jun 5, 2022

外部ライブラリのクラスのインスタンスとかはどうやって注入するんだろう

これが謎

@syuilo
Copy link
Member Author

syuilo commented Jul 13, 2022

https://github.com/microsoft/tsyringe
でも良さそう

@syuilo
Copy link
Member Author

syuilo commented Aug 4, 2022

外部ライブラリのクラスのインスタンスとかはどうやって注入するんだろう

これが謎

こんな感じでラップしたクラスを作るのが正解っぽい?
https://github.com/inversify/inversify-express-example/blob/master/MongoDB/utils/mongodb/client.ts

大変そう

@syuilo
Copy link
Member Author

syuilo commented Aug 24, 2022

ヌァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァァンンンンオオオオンンオンオンオンオンンンンンンンンン゛ン゛!!!!!!!!!!!!!!!!

@syuilo syuilo mentioned this issue Sep 6, 2022
1 task
@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

外部ライブラリのクラスのインスタンスとかはどうやって注入するんだろう

文字列指定でcontainerに値を登録 & serviceにinjectできるっぽい

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

やっていく
https://github.com/misskey-dev/misskey/tree/di

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

外部ライブラリのクラスのインスタンスとかはどうやって注入するんだろう

文字列指定でcontainerに値を登録 & serviceにinjectできるっぽい

正しい使い方なのか(外部ライブラリのクラスのインスタンスを注入する目的を想定しているのか)は謎

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

テスト書くときはどうすんだこれ

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

tasukete

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

全然情報がない

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

テストの際に特定のserviceだけモックに置き換えるのってどうするんだ

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

ンニャゴゴゴゴゴゴゴゴ

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

@syuilo
Copy link
Member Author

syuilo commented Sep 6, 2022

特定のメソッドだけ差し替えるのは出来ないの

@syuilo
Copy link
Member Author

syuilo commented Sep 9, 2022

Nest.jsのDI部分だけを利用することもできそう

これなら一般的なRESTサービスとはちょっと違うMisskeyでも使えそう

@syuilo
Copy link
Member Author

syuilo commented Sep 10, 2022

Nest使うか...

@syuilo
Copy link
Member Author

syuilo commented Sep 17, 2022

やった

@syuilo syuilo closed this as completed Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️Dev Development of Misskey itself 🔥high priority 💚Refactor Rewriting code without changing behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant