Author image

Registry - Dependency Injection Container Design Pattern


Registry lets you establish a single point of access for objects. Registry is often used as a Dependency Injection container (DIC). A DIC is a singleton class with a hash map container of various singleton types as well as functions querying the map. The queries are done and we return a certain object from the container. This hash-map is the provider of objects originating from a common interface and which they can be reused by whoever's asking (so it's best for them to be of the type std::shared_ptr<Type>). The objects stay resident inside DIC.

Since we want to avoid duplications, we implicitly want to "share" instances of objects; this requirement is screaming out for shared_ptr

1