2014-10-03 20:34:37 -04:00
|
|
|
import {CONST} from "facade/lang";
|
|
|
|
|
2014-10-14 16:00:35 -04:00
|
|
|
/**
|
|
|
|
* A parameter annotation that creates a synchronous eager dependency.
|
|
|
|
*
|
|
|
|
* class AComponent {
|
|
|
|
* constructor(@Inject('aServiceToken') aService) {}
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2014-10-03 20:34:37 -04:00
|
|
|
export class Inject {
|
|
|
|
@CONST()
|
2014-10-07 10:34:07 -04:00
|
|
|
constructor(token) {
|
2014-10-03 20:34:37 -04:00
|
|
|
this.token = token;
|
|
|
|
}
|
2014-10-05 16:25:42 -04:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:00:35 -04:00
|
|
|
/**
|
|
|
|
* A parameter annotation that creates an asynchronous eager dependency.
|
|
|
|
*
|
|
|
|
* class AComponent {
|
|
|
|
* constructor(@InjectPromise('aServiceToken') aServicePromise) {
|
|
|
|
* aServicePromise.then(aService => ...);
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2014-10-10 15:44:56 -04:00
|
|
|
export class InjectPromise {
|
2014-10-05 16:25:42 -04:00
|
|
|
@CONST()
|
2014-10-07 10:34:07 -04:00
|
|
|
constructor(token) {
|
2014-10-05 16:25:42 -04:00
|
|
|
this.token = token;
|
|
|
|
}
|
2014-10-06 13:45:24 -04:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:00:35 -04:00
|
|
|
/**
|
|
|
|
* A parameter annotation that creates a synchronous lazy dependency.
|
|
|
|
*
|
|
|
|
* class AComponent {
|
|
|
|
* constructor(@InjectLazy('aServiceToken') aServiceFn) {
|
|
|
|
* aService = aServiceFn();
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2014-10-06 13:45:24 -04:00
|
|
|
export class InjectLazy {
|
|
|
|
@CONST()
|
2014-10-07 10:34:07 -04:00
|
|
|
constructor(token) {
|
2014-10-06 13:45:24 -04:00
|
|
|
this.token = token;
|
|
|
|
}
|
2014-10-09 12:09:50 -04:00
|
|
|
}
|
2014-10-14 16:00:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* `DependencyAnnotation` is used by the framework to extend DI.
|
|
|
|
*
|
|
|
|
* Only annotations implementing `DependencyAnnotation` will be added
|
|
|
|
* to the list of dependency properties.
|
|
|
|
*
|
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* class Parent extends DependencyAnnotation {}
|
|
|
|
* class NotDependencyProperty {}
|
|
|
|
*
|
|
|
|
* class AComponent {
|
|
|
|
* constructor(@Parent @NotDependencyProperty aService:AService) {}
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* will create the following dependency:
|
|
|
|
*
|
|
|
|
* new Dependency(Key.get(AService), [new Parent()])
|
|
|
|
*
|
|
|
|
* The framework can use `new Parent()` to handle the `aService` dependency
|
|
|
|
* in a specific way.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export class DependencyAnnotation {
|
|
|
|
@CONST()
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
}
|