1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.bindContribution = exports.bindContributionProvider = exports.Bindable = exports.ContributionProvider = void 0;
|
19 | const contribution_filter_1 = require("./contribution-filter");
|
20 | exports.ContributionProvider = Symbol('ContributionProvider');
|
21 | class ContainerBasedContributionProvider {
|
22 | constructor(serviceIdentifier, container) {
|
23 | this.serviceIdentifier = serviceIdentifier;
|
24 | this.container = container;
|
25 | }
|
26 | getContributions(recursive) {
|
27 | if (this.services === undefined) {
|
28 | const currentServices = [];
|
29 | let filterRegistry;
|
30 | let currentContainer = this.container;
|
31 |
|
32 | while (currentContainer !== null) {
|
33 | if (currentContainer.isBound(this.serviceIdentifier)) {
|
34 | try {
|
35 | currentServices.push(...currentContainer.getAll(this.serviceIdentifier));
|
36 | }
|
37 | catch (error) {
|
38 | console.error(error);
|
39 | }
|
40 | }
|
41 | if (filterRegistry === undefined && currentContainer.isBound(contribution_filter_1.ContributionFilterRegistry)) {
|
42 | filterRegistry = currentContainer.get(contribution_filter_1.ContributionFilterRegistry);
|
43 | }
|
44 |
|
45 | currentContainer = recursive === true ? currentContainer.parent : null;
|
46 | }
|
47 | this.services = filterRegistry ? filterRegistry.applyFilters(currentServices, this.serviceIdentifier) : currentServices;
|
48 | }
|
49 | return this.services;
|
50 | }
|
51 | }
|
52 | var Bindable;
|
53 | (function (Bindable) {
|
54 | function isContainer(arg) {
|
55 | return typeof arg !== 'function'
|
56 |
|
57 |
|
58 | && ('guid' in arg || 'parent' in arg);
|
59 | }
|
60 | Bindable.isContainer = isContainer;
|
61 | })(Bindable = exports.Bindable || (exports.Bindable = {}));
|
62 | function bindContributionProvider(bindable, id) {
|
63 | const bindingToSyntax = (Bindable.isContainer(bindable) ? bindable.bind(exports.ContributionProvider) : bindable(exports.ContributionProvider));
|
64 | bindingToSyntax
|
65 | .toDynamicValue(ctx => new ContainerBasedContributionProvider(id, ctx.container))
|
66 | .inSingletonScope().whenTargetNamed(id);
|
67 | }
|
68 | exports.bindContributionProvider = bindContributionProvider;
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function bindContribution(bindable, service, contributions) {
|
77 | const bind = Bindable.isContainer(bindable) ? bindable.bind.bind(bindable) : bindable;
|
78 | for (const contribution of contributions) {
|
79 | bind(contribution).toService(service);
|
80 | }
|
81 | }
|
82 | exports.bindContribution = bindContribution;
|
83 |
|
\ | No newline at end of file |