title: Pattern to enable customization through DI
body: <p>I'm looking at the implementation of <a href="https://github.com/angular/in-memory-web-api/blob/master/src/in-memory-backend.service.ts#L257" rel="nofollow noreferrer">in-memory-web-api</a> and there is the following code:</p>
  
  <pre><code>@Injectable()
  export class InMemoryBackendService {
    protected config: InMemoryBackendConfigArgs = new InMemoryBackendConfig();
              ^^^^^^
    ...
  
        constructor(
          @Inject(InMemoryBackendConfig) @Optional() config: InMemoryBackendConfigArgs 
                                                     ^^^^^^
          ) {
          ...
  </code></pre>
  
  <p>As I understand the pattern is the following:</p>
  
  <ol>
  <li>Defined class property and instantiate a dependency without using DI</li>
  <li>Optionally inject dependency</li>
  </ol>
  
  <p>If a user provides modified dependency through DI, it will be injected and the default one instantiated without DI will be overridden. I suspect something similar maybe with <code>RequestOptions</code> in <code>HTTP</code> module.</p>
  
  <p>Is this a common pattern?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>It turns out that <code>in-memory-web-api</code> is not exactly the pattern I'm asking about. Suppose, I have a class <code>A</code> that uses instance of class <code>B</code> injectable with the token <code>B</code>. So they are both registered with the root injector:</p>
  
  <p>providers: [A, B]</p>
  
  <p>Now, if a user wants to customize <code>B</code>, he can register the customized version under the same token, thus effectively overrriding the original <code>B</code>:</p>
  
  <pre><code>providers: [{provide:B, useClass: extendedB}]`
  </code></pre>
  
  <p>This is how <code>RequestOptions</code> can be extended in <code>http</code> module.</p>