-
Notifications
You must be signed in to change notification settings - Fork 1
/
composition-root.ts
56 lines (50 loc) · 2.19 KB
/
composition-root.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
import axios from "axios";
import { AppConfiguration, AppServices } from "./abstractions/application";
import { AppConfigurationRendererImplementation } from "./implementations/AppConfigurationRendererImplementation";
import { SessionMfeAppSessionStateClient } from "./implementations/session-mfe/SessionMfeAppSessionStateClient";
import {
ServicesFactories,
SingletonLazyAppServicesContainer,
} from "./implementations/SingletonLazyAppServicesContainer";
import { defaultAppConfiguration } from "./default-configuration";
import { IntegrationsApiClientImpl } from "./implementations/integrations-api/IntegrationsApiClientImpl";
import { DummyIntegrationsApiClient } from "./implementations/dummies/integrations-api-client";
export const configureApp = (
customConfiguration: Partial<AppConfiguration>,
): AppServices => {
const appConfiguration = {
...defaultAppConfiguration,
...customConfiguration,
};
const realFactories: ServicesFactories = {
windowFactory: () => window,
axiosStaticFactory: () => axios,
appConfigurationFactory: () => appConfiguration,
appConfigurationRendererFactory: (appServices: AppServices) =>
new AppConfigurationRendererImplementation(appServices),
appSessionStateMonitorFactory: ({ window }: AppServices) =>
new SessionMfeAppSessionStateClient({ window }),
appSessionStateAccessorFactory: ({ appSessionStateMonitor }: AppServices) =>
// Casting because the same instance of SessionMfeAppSessionStateClient
// will be use for appSessionStateMonitor and appSessionStateAccessor
appSessionStateMonitor as SessionMfeAppSessionStateClient,
integrationsApiClientFactory: ({
axiosStatic,
appSessionStateAccessor,
appConfiguration,
}) =>
new IntegrationsApiClientImpl({
axiosStatic,
appSessionStateAccessor,
appConfiguration,
}),
};
const dummyFactories: Partial<ServicesFactories> = {
integrationsApiClientFactory: () => new DummyIntegrationsApiClient(),
};
const factories = appConfiguration.useDummies
? { ...realFactories, ...dummyFactories }
: realFactories;
const appServices = new SingletonLazyAppServicesContainer(factories);
return appServices;
};