Skip to main content

Practice · 3 of 3

Wire the Composition Root

CHALLENGE
Difficulty: intermediate+25 XP

Build an app object with a BuildApp(config) method that registers an IClock (singleton, provided FakeClock), an IPriceCalculator (transient, provided), and returns the fully-resolved App. The App must be able to quote a price with the current time. ``csharp public interface IClock { DateTime Now { get; } } public sealed class FakeClock : IClock { public FakeClock(DateTime now); public DateTime Now { get; } } public interface IPriceCalculator { decimal Quote(decimal basePrice, DateTime at); } public sealed class RushCalculator : IPriceCalculator { /* +10% before 9am */ } public sealed class App { public App(IPriceCalculator calc, IClock clock); public string Quote(decimal p); } static Solution.App BuildApp(Solution.FakeClock clock); ``

Back to lesson: Practice: DI Practice: Fakes, Lifetimes, Wiring