-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.ts
46 lines (40 loc) · 1.92 KB
/
App.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { Container } from "inversify";
import { Bindable } from "@itwin/cloud-agnostic-core";
import { ClientStorageDependency } from "@itwin/object-storage-core";
import { FileDownloader } from "../FileDownloader";
/**
* This class is an example of a minimal application that depends on generic
* `ClientStorage` class. It is not aware of any implementations of
* `ClientStorage` which are configured at runtime. The caller uses
* `Bindable.useBindings` method to register specific implementations for
* required dependencies (see Run.ts file in this directory).
*/
export class App extends Bindable {
public container = new Container();
/**
* The app constructor defines that it requires `ClientStorage` dependency
* and relies on its startup to append container configuration by binding a
* specific `ClientStorage` implementation.
*/
constructor() {
super();
this.requireDependency(ClientStorageDependency.dependencyType);
this.container.bind(FileDownloader).toSelf().inSingletonScope();
}
/**
* For every dependency registered in `App` constructor, `bindDependencies`
* selects one set of bindings based on config and adds it to the dependency
* injection container. Delaying this `bindDependencies` call until the start
* method allows us to rebind config to a different value and to register
* additional implementations that `App` does not have access to.
*/
public async start(): Promise<void> {
this.bindDependencies(this.container);
const fileDownloader = this.container.get(FileDownloader);
await fileDownloader.downloadFile();
}
}