-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositionRoot.ts
52 lines (43 loc) · 1.72 KB
/
compositionRoot.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
import { JournalModule } from "../../modules/journal/journalModule.ts";
import { App } from "../app/app.ts";
import { JournalRepository } from "../../modules/journal/journalRepository.ts";
import { JournalController } from "../../modules/journal/journalController.ts";
import { JournalPresenter } from "../../modules/journal/journalPresenter.ts";
import { InMemoryClientStorage } from "../../modules/journal/infra/repos/inMemoryClientStorage.ts";
import { LocalStorageClient } from "../../modules/journal/infra/repos/localStorageClient.ts";
import { ClientStorageRepository } from "../../modules/journal/clientStorageRepository.ts";
type Context = "test" | "dev" | "prod";
export class CompositionRoot {
private readonly context: Context;
private readonly app: App;
private clientStorage: ClientStorageRepository | undefined;
private journalRepository: JournalRepository | undefined;
constructor(context: Context = "dev") {
this.context = context;
const journalModule = this.createJournalModule();
this.app = new App({ journalModule });
}
createJournalModule() {
if (this.context === "test") {
this.clientStorage = new InMemoryClientStorage();
} else {
this.clientStorage = new LocalStorageClient();
}
this.journalRepository = new JournalRepository(this.clientStorage);
const journalController = new JournalController(this.journalRepository);
const journalPresenter = new JournalPresenter(this.journalRepository, this.clientStorage);
return new JournalModule(
journalController,
journalPresenter,
);
}
getApp() {
return this.app;
}
getClientStorage() {
return this.clientStorage;
}
getJournalRepository() {
return this.journalRepository;
}
}