inversify/ node js

This mind map outlines key concepts related to dependency injection and its implementation across various contexts, particularly using the Inversify library. It covers the following main topics: Function Injection: Explains dependency binding with bindDependencies, emphasizing the distinction between actions before and after binding dependencies. Initialization: Discusses how to configure and initialize an IoC container with Inversify, including middleware injection for Express.js and Rabbit...

Get Started. It's Free
or sign up with your email address
inversify/ node js by Mind Map: inversify/ node js

1. others

1.1. styles

1.1.1. bad

1.1.2. good

1.1.3. not as good

1.1.4. not as bad

1.1.5. important

1.1.6. warning

1.1.7. link

1.2. AUTHOR

1.2.1. Nima Shokouhfar

1.2.1.1. Linkedin

1.2.1.1.1. Follow me on LinkedIn to stay updated on my latest professional insights and tech projects!

1.2.1.2. Youtube

1.2.1.2.1. code with nima

1.2.1.2.2. ideariver

1.2.1.3. Medium

1.2.1.3.1. ✍️ Follow me on Medium to read my latest articles on tech, coding, and innovation!

1.2.1.4. Github

1.2.1.4.1. ⭐️ Give my projects a star on GitHub and explore my repositories to discover new tools and innovations!

1.2.1.4.2. 💖 Sponsor me on GitHub to support my open-source contributions and help me create even more useful projects!

1.2.1.5. upwork

1.2.1.5.1. 💼 Hire me on Upwork for freelance projects. Let’s work together to bring your tech ideas to life!

1.2.1.6. main website: ideariver.ca

1.2.1.6.1. 🚀 Visit IdeaRiver.ca for all my latest projects, blogs, and ways to connect!

2. main

2.1. function injection

2.1.1. bindDependencies

2.2. this and the next are not the same

2.2.1. Everything done before binding, but the entire thing is wrao in a bigger function. As a result, after the execution of the function the const is undefined, and your dependency is gone

2.2.1.1. const initContainer=async ()=>{ I do my stuff here create const here }

2.2.2. Everything done after binding

2.2.2.1. never ever do this

2.2.2.2. this does not guarantee.

2.2.2.2.1. you don't know the user uses await or not. That can mess the user up

2.2.2.3. In other words, you don't want async stuff in your binding

2.2.3. just pass constant

2.2.3.1. const channel = await req.container.get<Channel>(TYPES.RabbitMQChannel);

2.2.3.2. easy

2.3. initialization

2.3.1. import { Container } from "inversify"; // Create and configure the IoC container const container = new Container();

2.3.2. front/end vs back end

2.3.2.1. express

2.3.2.1.1. middleware

2.3.2.2. react

2.3.2.2.1. inversify-react

2.4. Common injection that I use

2.4.1. default

2.4.1.1. container .bind<ISessionManager<User>>(TYPES.SessionManager) .to(TypeORMSessionManager); break;

2.4.1.1.1. interface to implementation

2.4.2. toConstant

2.4.2.1. container.bind(TYPES.RabbitMQChannel).toConstantValue(async () => { return channel; });

2.4.3. toDynamic

2.4.3.1. // Bind the repository to the container using TYPES.UserRepository container .bind<Repository<User>>(TYPES.UserRepository) .toDynamicValue(() => { return dataSource.getRepository(User); });