forked from internxt/drive-desktop
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBackupsDependencyContainerFactory.ts
More file actions
54 lines (44 loc) · 2.24 KB
/
BackupsDependencyContainerFactory.ts
File metadata and controls
54 lines (44 loc) · 2.24 KB
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
import { Container } from 'diod';
import { Environment } from '@internxt/inxt-js';
import { backgroundProcessSharedInfraBuilder } from '../../shared/dependency-injection/background/backgroundProcessSharedInfraBuilder';
import { registerFilesServices } from './virtual-drive/registerFilesServices';
import { registerFolderServices } from './virtual-drive/registerFolderServices';
import { registerLocalFileServices } from './local/registerLocalFileServices';
import { BackupService } from '../BackupService';
import { registerRemoteTreeServices } from './virtual-drive/registerRemoteTreeServices';
import { DependencyInjectionUserProvider } from '../../shared/dependency-injection/DependencyInjectionUserProvider';
import { DownloaderHandlerFactory } from '../../../context/storage/StorageFiles/domain/download/DownloaderHandlerFactory';
import { EnvironmentFileDownloaderHandlerFactory } from '../../../context/storage/StorageFiles/infrastructure/download/EnvironmentRemoteFileContentsManagersFactory';
import { RemoteTreeBuilder } from '../../../context/virtual-drive/remoteTree/application/RemoteTreeBuilder';
import { SimpleFolderCreator } from '../../../context/virtual-drive/folders/application/create/SimpleFolderCreator';
export class BackupsDependencyContainerFactory {
private static container: Container | null = null;
static async build(): Promise<Container> {
if (this.container) {
return this.container;
}
const builder = await backgroundProcessSharedInfraBuilder();
const user = DependencyInjectionUserProvider.get();
registerFilesServices(builder);
registerFolderServices(builder);
registerRemoteTreeServices(builder);
registerLocalFileServices(builder);
builder
.register(DownloaderHandlerFactory)
.useFactory((c) => new EnvironmentFileDownloaderHandlerFactory(c.get(Environment), user.backupsBucket));
builder.register(BackupService).useFactory((c) => {
return new BackupService(
c.get(RemoteTreeBuilder),
c.get(SimpleFolderCreator),
c.get(Environment),
user.backupsBucket,
);
});
this.container = builder.build();
return this.container;
}
static async reinitialize(): Promise<Container> {
this.container = null;
return this.build();
}
}