Registry Pattern

  1. Motivation 
    1. To Create a well-known object that other objects can use to find common objects and services.
  2. Summary 
    1. Very basic and classic pattern that suggest to have a central location for object of common interested. 
    2. A Registry is essentially a global object, or at least it looks like one even if it isn't as global as it may appear.
    3. Registries are generally implemented as singleton.
    4. It is not very much encouraged as it is also treated as Anti Pattern
  3. When to Use 
    1. We should usually avoid using registry pattern because it violates encapsulation principle.
    2. Registry should be only used when there is no other ways to share data in between the object of same scope. 
    3. Alternative to registry could be 
      1. Parent/Caller Context could be another alternative in which caller passed it own context (usually "this" pointer) to called function either via constructor or by adding an extra parameter to method being called)
  4. Registry Scope
    1. Visibility of Registry can be defined at different scopes depending upon requirement  
      1. Thread Scoped
      2. Process Scoped
      3. Application Scoped
      4. System Scoped 
  5. Related Patterns
    1. Inversion of Control : Used for dynamic configuration of object loading.
    2. Service Locators : can use registry for mapping service metadata
    3. Dependency Injection : Allow you to implement registry configuration out side application like configuration file.
  6. References 
    1. MSDN:Patterns in the Composite Application Library
    2. MSDN: Why Registry Pattern is antipattern. And what is alternative for it.