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

Guide: Dependency Injection via the Fastify Plugin System #5190

Open
2 tasks done
matthyk opened this issue Dec 6, 2023 · 3 comments
Open
2 tasks done

Guide: Dependency Injection via the Fastify Plugin System #5190

matthyk opened this issue Dec 6, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@matthyk
Copy link
Contributor

matthyk commented Dec 6, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I am currently working on a talk about the capability to do dependency injection through Fastify's plugin system without using an IoC container, as you might know from the Java ecosystem or the popular Node.js framework Nest.js. Would there be any interest in a guide explaining how to use this specifically in Fastify (with and without TypeScript) and how it can be used to mock dependencies during testing?
If so, I would be happy to write the guide over the next few weeks while I have to prepare the talk anyway.

@mcollina
Copy link
Member

mcollina commented Dec 6, 2023

Definitely!

@metcoder95 metcoder95 added the documentation Improvements or additions to documentation label Dec 6, 2023
@jsumners
Copy link
Member

jsumners commented Dec 6, 2023

I assert that the fastify instance is very similar to an IoC container.

@matthyk
Copy link
Contributor Author

matthyk commented Mar 4, 2024

I have the feeling that there is still a lot of confusion when testing Fastify applications. I think the main reason for this is Fastify's plugin system and the resulting encapsulation. Because there are different contexts but you can only access the root context directly, the classic mocking/spying is not possible as you might know it from other frameworks. I would therefore suggest taking a different thematic approach to the guide that I originally proposed, and rather address the problems discussed above and discuss possible solutions. There are already plugins written by the community that address these problems, which solve the problem in different ways. You could therefore see this guide as a collection of different solutions and test strategies.For example:

Here are some discussions/StackOverflow questions around this topic:

What are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants