Code Modularity and Boundary Enforcement
Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby - Shopify

Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby - Shopify

3/19/2021

What this post added

Introduced the Repository pattern and Dependency Injection to resolve circular dependencies between a pricing gem and its consumers (Shopify Core monolith and Storefront Renderer). Defined a contract using a `PricingRepositoryInterface` and common Schema objects within the gem. Implemented the interface in each consumer to access their specific data sources. Leveraged Sorbet for type safety, enforcing the contract and improving code clarity. Outlined testing strategies including mocks for isolated gem testing and integration tests for consumer-gem interaction.

Read the original post ↗