-
Notifications
You must be signed in to change notification settings - Fork 0
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
multibindingcomes 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-architectureadheres to theopen-closed principlemeaning it isopen for extensionandclosed for modification.