Wiring Services in Frameworks And How it Works Under the Hood

The Most Important Question i have asked myself when i have started learning Clean Architecture like DDD (Domain Driven Development) and Separating Business Logic in Services What is the Best Practices Should i follow To Make the Communication Between …


This content originally appeared on DEV Community and was authored by eslamelkholy

The Most Important Question i have asked myself when i have started learning Clean Architecture like DDD (Domain Driven Development) and Separating Business Logic in Services What is the Best Practices Should i follow To Make the Communication Between Services Better?
Today we will discuss alot of Things Related to The Communication between Classes And How it Works in Most Of Frameworks Like Nestjs and Laravel,....

First Of All You Must Read this Quote Twice

Every App is The Result of Aggregation of Several Components and App Grows, the Way we connect these Components Becomses Win Or Lose Factor For the Maintainability and Success Of The Project
This Great Quote From Nodejs Design Patterns Book And Most of Code Snippets Also

Now Let's Start

we Have a 1-Blog Service and 2-User Service
we want To Use Blog Service in User Service because User Service Depends on Blog Service

Two Services Depends On Each Other

But if We Have More Service Like Friends Service and User Service Depends on Both So We Going to Create a new Object in every New One?

Three Services Connected With Each Other

The First Thing Comes in your Mind is to Make It as Singleton
Singleton Object And Uses it Every where it's an ideal Solution for Wiring Modules But This Solution Still Have a bottlenecks That Can Easily Solved By

Dependency Injection

  • Mock Our Services
  • Improved Decoupling Between Modules
  • Let's Say i will change the whole Object Also
  • Understand the Relationship Between Components

Dependency Injection + Singleton

it's The Ideal Solution For Wiring Modules Together and how we can easily Control the flow And Dependency Tree With These To That Exactly The Same what IOC(Inversion of Control) Containers Do For Wiring The Modules Together Uses

Dependency Injection + Singleton
Makes the Communication between these Modules Easily And helps us To Solve Many Problems Related to Wiring Services Together

that's why most of Frameworks Already Using IOC Containers To Shift Responsibility Of Wiring Modules To Third Party Package and how it Actually Works Under the hood and Injects Services Easily With Each other

References

Nodejs Design Pattern Book

Refactoring Guru Design Patterns


This content originally appeared on DEV Community and was authored by eslamelkholy


Print Share Comment Cite Upload Translate Updates
APA

eslamelkholy | Sciencx (2021-06-26T14:44:57+00:00) Wiring Services in Frameworks And How it Works Under the Hood. Retrieved from https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/

MLA
" » Wiring Services in Frameworks And How it Works Under the Hood." eslamelkholy | Sciencx - Saturday June 26, 2021, https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/
HARVARD
eslamelkholy | Sciencx Saturday June 26, 2021 » Wiring Services in Frameworks And How it Works Under the Hood., viewed ,<https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/>
VANCOUVER
eslamelkholy | Sciencx - » Wiring Services in Frameworks And How it Works Under the Hood. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/
CHICAGO
" » Wiring Services in Frameworks And How it Works Under the Hood." eslamelkholy | Sciencx - Accessed . https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/
IEEE
" » Wiring Services in Frameworks And How it Works Under the Hood." eslamelkholy | Sciencx [Online]. Available: https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/. [Accessed: ]
rf:citation
» Wiring Services in Frameworks And How it Works Under the Hood | eslamelkholy | Sciencx | https://www.scien.cx/2021/06/26/wiring-services-in-frameworks-and-how-it-works-under-the-hood/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.