Before beginning with this article, if you want to know about Dependency Injection first, please take look at the below article:


Lazy loading is on-demand-loading. It’s an optimization technique that can be helpful in many use cases.


In Dependency injection, we load all the dependencies required in the project in the beginning. When you are developing local systems Dependency injection might serve everything well. Let’s take this case to the server where many users want to connect to your services. Loading unnecessary services might consume a lot of memory and obviously, you might want to prevent it. 


Instantiate when necessary!


Some services like Routing and Database can be critical which are generally initialized in beginning for all requests. So other services like Validation can be instantiated when necessary during form data processing. Although every process is lazy loaded as each time instantiate is required. So, any developer needs to see if unused services are instantiated unnecessarily during application load.




If you are looking for dependency injection in JavaScript I would highly recommend Box by Haluka Framework for Dependency Injection.