Service Location

Our current implementation of the MailService class relies on the calling code to create an instance of the ISystemSettings interface, and pass this through in the constructor. When we write code that creates an instance of the MailService class, we are therefore forced to provide the ISystemSettings interface at the time of construction. This is a compile-time dependency. In other words, changing the instance of ISystemSettings requires changes to the source code, and then recompilation. It would be far better, however, if we set these options at runtime.

In order to accomplish this, the MailService class needs to request an instance of the class that is implementing the ISystemSettings interface at runtime, not at compile ...

Get Mastering TypeScript 3 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.