Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created November 12, 2014 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/1e8bacc182ecc9393072 to your computer and use it in GitHub Desktop.
Save OliverJAsh/1e8bacc182ecc9393072 to your computer and use it in GitHub Desktop.
DI: ApiClient -> HttpAdapter
/* jshint esnext: true */
import * as di from 'di/src';
class HttpAdapter {
constructor() {
console.log('HttpAdapter constructor');
}
}
class ApiClient {
constructor(httpAdapter) {
console.log('ApiClient constructor httpAdapter: %s', httpAdapter);
}
}
// TODO: Fix ES6 class annotations
// As per: https://github.com/angular/di.js/issues/80
di.annotate(ApiClient, new di.Inject('HttpAdapter'));
di.annotate(run, new di.Inject(HttpAdapter));
di.annotate(run, new di.InjectLazy(ApiClient));
function run(httpAdapter, createApiClient) {
createApiClient('HttpAdapter', httpAdapter);
}
var injector = new di.Injector();
injector.get(run);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment