Using a Dependency Injection Container
Problem
I have resolved my dependency issue, but how do I instantiate the concrete implementation of interfaces without creating
dependencies somewhere else in the application?
As it stands, I still have to have statements somewhere in the application like
these:
...
IEmailSender sender = new MyEmailSender();
helper = new PasswordResetHelper(sender);
Solution
The answer is to use a dependency injection container, also known as an IoC container. This is a component that acts as a
broker between the dependencies that a class like PasswordResetHelper declares and the classes that can be used to
resolve those dependencies, such as MyEmailSender.
No comments:
Post a Comment