In the previous chapter, you saw how dependency injection (DI) works and how to use the constructor injection method. But, if you need to inject many instances during runtime, this method can be quite cumbersome and can make it complicated to understand and maintain your code.
Therefore, you can use a more advanced technique of DI called method injection. This allows accessing instances directly from within your code.
In the following example, you are going to add a new service for handling game invitations and update the Tic-Tac-Toe application for being able to send emails for contacting other users to join a game, while using method injection:
- Add a new service called GameInvitationService ...