February 2019
Beginner
694 pages
18h 4m
English
Earlier, we discussed the benefits and anti-patterns at play when using a service locator pattern, and picked up on Mark Seeman's ideas that DI should only occur on class constructors. We have been using Service Location in our MailService class within the constructor function, as follows:
export default class MailService {
private _transporter: nodemailer.Transporter;
private _settings: ISystemSettings;
constructor() {
this._settings =
ServiceLocator.resolve('ISystemSettings');
this._transporter = nodemailer.createTransport(
this._settings.SmtpServerConnectionString
);
}
Here, we have specified a local _settings property of type ISystemSettings, and are using the ServiceLocator to resolve this internal property. The ...
Read now
Unlock full access