-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-implementation-helper.ts
67 lines (56 loc) · 2.44 KB
/
base-implementation-helper.ts
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
import {
interfaces,
Container,
injectable, inject,
} from 'inversify';
import { APP_CONTAINER, REMOTE_ACTOR_PROXY_FACTORY } from '../../../symbols';
import { ActorProxyFactory } from '../../actor/proxy/actor-proxy-factory';
import { Newable } from '../../../implementation';
import { DEFAULT_ACTOR_TASK_LIST } from '../../../constants';
import { ACTOR_CLIENT_TAG, TASK_LIST_TAG } from '../../actor/decorators/actor-decorators';
import { Binding, ImplementationHelper } from '../../generics/implementation-helper';
import Metadata = interfaces.Metadata;
import { WORKFLOW_REMOTE_CLIENT_FACTORY, WorkflowClientFactory } from '../../workflow/workflow-client-factory';
import { WORKFLOW_CLIENT_TAG } from '../../workflow/decorators/workflow-client-decorators';
import { RemoteWorkflowStub } from '../../workflow/workflow-proxy';
@injectable()
export class BaseImplementationHelper implements ImplementationHelper {
constructor(@inject(APP_CONTAINER)
private appContainer: Container,
@inject(REMOTE_ACTOR_PROXY_FACTORY)
private actorProxyFactory: ActorProxyFactory,
@inject(WORKFLOW_REMOTE_CLIENT_FACTORY)
private workflowClientFactory: WorkflowClientFactory) {
}
private static getValueFromMetadata(metadatas: Metadata[], key: any): any {
const meta = metadatas.find(meta => meta.key === key);
if (meta) {
return meta.value;
}
}
public addImplementations(implementationList: Binding[]): void {
implementationList.forEach((binding) => {
const impl: Newable<any> = binding.impl;
/*
Load default actor implementation
*/
this.appContainer.bind<Newable<any>>(binding.key)
.to(impl).whenTargetIsDefault();
/*
Load actor clients
*/
this.appContainer.bind<Newable<any>>(binding.key)
.toDynamicValue((req) => {
const customTags = req.currentRequest.target.getCustomTags();
const taskList = BaseImplementationHelper.getValueFromMetadata(customTags, TASK_LIST_TAG);
return this.actorProxyFactory.create(impl, taskList ? taskList : DEFAULT_ACTOR_TASK_LIST);
}).whenTargetTagged(ACTOR_CLIENT_TAG, true);
/*
Load workflow client definitions
*/
this.appContainer.bind<RemoteWorkflowStub<any>>(binding.key)
.toDynamicValue(() => this.workflowClientFactory.create(binding.impl))
.whenTargetTagged(WORKFLOW_CLIENT_TAG, true);
});
}
}