Understanding dependency injection
When we have dependencies between smart contracts, the dependent smart contract would need an instance of the independent smart contract to invoke its function. There are two choices in such cases: either the smart contract itself creates a new instance of the contract, or it might already expect the smart contract instance to be available. If the dependent smart contract creates a new instance, it will have an instance address directly available using the new
keyword, and if it expects the instance to be already available, then the address of the contract instance must be supplied to the dependent smart contract.
Supplying the address of the independent smart contract instance is also known as injection or, in other words, the dependencies of a smart contract are injected at runtime rather than the dependencies getting created at design time. Using the new
keyword is a design-time static creation of a smart contract.
The dependencies or independent...