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

DevFeed: [Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby](<https://devfeed.tech/articles/remove-circular-dependencies-by-using-dependency-injection-and-the-repository-pattern-in-ruby-1550.md>)

Original publisher: [Read original article](<https://shopify.engineering/repository-pattern-ruby>)

Author: Ignacio Chiazzo

Published: 2021-03-19T15:00:00Z

Content type: tutorial

Language: en

Sources: [Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering.md>), [Shopify Engineering - Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering-shopify-engineering.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [data](<https://devfeed.tech/tags/data.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [performance](<https://devfeed.tech/tags/performance.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [shopify](<https://devfeed.tech/tags/shopify.md>)

## AI overview

A Ruby tutorial on using dependency injection and the Repository pattern to break circular dependencies between a shared gem and its consumer applications. It also discusses using Sorbet to make the implementation typed and cleaner.

## Source excerpt

There are dependencies between gems and the platforms that use them. In scenarios where the platforms have the data and the gem has the knowledge, there is a direct circular dependency between the two and both need to talk to each other. I'll show you how we used the Repository pattern in Ruby to remove that circular dependency and help us make gems thin and stateless. Plus, I'll show you how using Sorbet in the implementation made our code typed and cleaner.