blob: 4918d30927d6f2c5a71f409dc2fedcb8d6eb44d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import * as ERROR_MSGS from "../constants/error_msgs";
import { BindingTypeEnum } from "../constants/literal_types";
import { BindingInWhenOnSyntax } from "./binding_in_when_on_syntax";
import { BindingWhenOnSyntax } from "./binding_when_on_syntax";
var BindingToSyntax = (function () {
function BindingToSyntax(binding) {
this._binding = binding;
}
BindingToSyntax.prototype.to = function (constructor) {
this._binding.type = BindingTypeEnum.Instance;
this._binding.implementationType = constructor;
return new BindingInWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toSelf = function () {
if (typeof this._binding.serviceIdentifier !== "function") {
throw new Error("" + ERROR_MSGS.INVALID_TO_SELF_VALUE);
}
var self = this._binding.serviceIdentifier;
return this.to(self);
};
BindingToSyntax.prototype.toConstantValue = function (value) {
this._binding.type = BindingTypeEnum.ConstantValue;
this._binding.cache = value;
this._binding.dynamicValue = null;
this._binding.implementationType = null;
return new BindingWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toDynamicValue = function (func) {
this._binding.type = BindingTypeEnum.DynamicValue;
this._binding.cache = null;
this._binding.dynamicValue = func;
this._binding.implementationType = null;
return new BindingInWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toConstructor = function (constructor) {
this._binding.type = BindingTypeEnum.Constructor;
this._binding.implementationType = constructor;
return new BindingWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toFactory = function (factory) {
this._binding.type = BindingTypeEnum.Factory;
this._binding.factory = factory;
return new BindingWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toFunction = function (func) {
if (typeof func !== "function") {
throw new Error(ERROR_MSGS.INVALID_FUNCTION_BINDING);
}
var bindingWhenOnSyntax = this.toConstantValue(func);
this._binding.type = BindingTypeEnum.Function;
return bindingWhenOnSyntax;
};
BindingToSyntax.prototype.toAutoFactory = function (serviceIdentifier) {
this._binding.type = BindingTypeEnum.Factory;
this._binding.factory = function (context) {
var autofactory = function () { return context.container.get(serviceIdentifier); };
return autofactory;
};
return new BindingWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toProvider = function (provider) {
this._binding.type = BindingTypeEnum.Provider;
this._binding.provider = provider;
return new BindingWhenOnSyntax(this._binding);
};
BindingToSyntax.prototype.toService = function (service) {
this.toDynamicValue(function (context) { return context.container.get(service); });
};
return BindingToSyntax;
}());
export { BindingToSyntax };
|