Dependency inversion in Rust Web Application

  • Use case: app-specific business rules
  • Gateway: adapter between a data format (e.g., JSON or ORM ) and a particular Domain object
  • Port: abstraction depended by details (concrete implementations)

Use case

The news_get_usecase shows what the application can do: We can find 100 latest news. The Use case is not aware of the implementation details (Gateway). It is dependent on abstractions (Port).


The Port’s trait is implemented for the Gateway. The Use Case and The Gateway depend on the Port.


The Gateway implements the Port. It constructs Domain objects by reading from the I/O source and converts Domain objects to a data format to send to an external system (e.g., API Server, Database, Message queue, Object storage, or File system). This allows us to write code that the domain or business logic is independent of any external systems.

Closing thoughts

I design to increase the parameter in the Use case’s function when dependencies increase due to the increasing number of external systems. This will keep dependency relationships simple and make us concisely apply the dependency inversion pattern.



Software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store