Practice · 1 of 3
Invert a Hardwired Dependency
CHALLENGE
Difficulty: intermediate+25 XP
PriceNotifier currently news up SmtpEmailer directly (provided). Introduce IEmailer (Send(string, string)), make PriceNotifier take IEmailer via constructor, and implement a LoggingEmailer that records "log:<to>:<body>" into its Log list.
``csharp
public interface IEmailer { void Send(string to, string body); }
public sealed class SmtpEmailer : IEmailer { public void Send(...) { /* real */ } }
public sealed class PriceNotifier
{
public void Notify(string email, string product, decimal price);
}
``
Press Submit to check your solution.
Back to lesson: Practice: DI Practice: Fakes, Lifetimes, Wiring