Demo: dependency inversion for a payment provider
On This Lesson 3 topics
The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.
In this lesson
inject a payment provider through an interface. Prepares JNR-004-LAB1.
Draft outline details
Step by step
- Show
CheckoutServicecallingnew StripeClient()directly; tests need the network. - Extract the
PaymentProviderinterface. - Inject it through the constructor.
- Planned mistake: the interface exposes Stripe-specific types, so the core still depends on Stripe. Fix: use Shop's own types (
Money,Receipt) in the interface. - Write a fake provider for tests; run them without a network.
- Add a second provider without touching
CheckoutService.
Check your understanding
Where should the interface live?
Show answer
In the core, not in the provider's code.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.