3. Dependency Injection is a software design
pattern that allows the removal of hardcoded dependencies and makes it possible to
change them, whether at run-time or
compile-time.
37. We have moved out dependency of Booking class
outside of it.
And we will inject it to Booking class while creating
its object.
38. We are injecting object of EmailNotification to Booking class
via constructor while creating its object.
39. Now Booking class is completely independent of any
implementation of INotification
40. Congratulations you have just done something known as
Dependency Injection
Note: This was constructor injection same thing can also be achieved using property injection.
47. DI is also very helpful for
unit testing.
If we wanted to test Booking class and don’t want to worry about EmailNotification
or SMSNotification we can create mock implementation of INotification and
pass it to Booking class object during the test. Will discuss it in Unit Testing session.
48.
49. Dependency Injection is a software design
pattern that allows the removal of hardcoded dependencies and makes it possible to
change them, whether at run-time or
compile-time.
50. In Part – 2 we will see what is
Dependency Injection Container
and how to use it to move all the dependencies to it.