Skip to content

Dagger ‐ multi binding

Devrath edited this page Oct 8, 2023 · 1 revision
  • Normally in most scenarios we handle a single instance of objects but there are a bunch of scenarios where you might need to group a bunch of instances into a collection and get it injected. In such scenarios multibinding comes into play.
  • Consider you have the collections of shapes.
interface Shape
class Triangle : Shape
class Rectangle : Shape
class Circle : Shape
  • You can inject all the shapes in one set using dagger multi-bindings.
  • You can use multi-bindings to implement a plugin architecture, where several modules can contribute to individual plugin interface implementations so the central class can use the entire set of plugins.
  • This plugin-architecture adheres to the open-closed principle meaning it is open for extension and closed for modification.
Clone this wiki locally