Skip to content

Commit 7edf000

Browse files
committed
added elastic config to isolate from context
1 parent 705a96e commit 7edf000

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import config from '../../../../../apps/backoffice/backend/config/config';
2+
import ElasticConfig from '../../../../Shared/infrastructure/persistence/elasticsearch/ElasticConfig';
3+
4+
export class BackofficeElasticConfigFactory {
5+
static createConfig(): ElasticConfig {
6+
return {
7+
url: config.get('elastic.url')
8+
};
9+
}
10+
}

src/Contexts/Shared/infrastructure/persistence/elasticsearch/ElasticClientFactory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Client as ElasticClient } from '@elastic/elasticsearch';
2-
import config from '../../../../../apps/backoffice/backend/config/config';
32
import { Nullable } from '../../../domain/Nullable';
3+
import ElasticConfig from './ElasticConfig';
44

55
export class ElasticClientFactory {
66
private static clients: { [key: string]: ElasticClient } = {};
77

8-
static async createClient(contextName: string): Promise<ElasticClient> {
8+
static async createClient(contextName: string, config: ElasticConfig): Promise<ElasticClient> {
99
let client = ElasticClientFactory.getClient(contextName);
1010

1111
if (!client) {
12-
client = await ElasticClientFactory.createAndConnectClient();
12+
client = await ElasticClientFactory.createAndConnectClient(config);
1313

1414
ElasticClientFactory.registerClient(client, contextName);
1515
}
@@ -21,8 +21,8 @@ export class ElasticClientFactory {
2121
return ElasticClientFactory.clients[contextName];
2222
}
2323

24-
private static async createAndConnectClient(): Promise<ElasticClient> {
25-
const client = new ElasticClient({ node: config.get('elastic.url') });
24+
private static async createAndConnectClient(config: ElasticConfig): Promise<ElasticClient> {
25+
const client = new ElasticClient({ node: config.url });
2626

2727
return client;
2828
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type ElasticConfig = { url: string };
2+
3+
export default ElasticConfig;

src/apps/backoffice/backend/config/dependency-injection/Shared/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
factory:
1414
class: ../../../../../../Contexts/Shared/infrastructure/persistence/elasticsearch/ElasticClientFactory
1515
method: 'createClient'
16-
arguments: ['mooc']
16+
arguments: ['mooc', '@Apps.Backoffice.Backend.ElasticConfig']
1717

1818
Shared.QueryHandlersInformation:
1919
class: ../../../../../../Contexts/Shared/infrastructure/QueryBus/QueryHandlersInformation
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
services:
2-
Apps.Backoffice.Backend.MongoConfig:
3-
factory:
4-
class: ../../../../../../Contexts/Backoffice/Courses/infrastructure/persistence/BackofficeMongoConfigFactory
5-
method: 'createConfig'
2+
Apps.Backoffice.Backend.MongoConfig:
3+
factory:
4+
class: ../../../../../../Contexts/Backoffice/Courses/infrastructure/persistence/BackofficeMongoConfigFactory
5+
method: 'createConfig'
66

7-
Apps.Backoffice.Backend.controllers.StatusGetController:
8-
class: ../../../controllers/StatusGetController
9-
arguments: []
7+
Apps.Backoffice.Backend.ElasticConfig:
8+
factory:
9+
class: ../../../../../../Contexts/Backoffice/Courses/infrastructure/persistence/BackofficeElasticConfigFactory
10+
method: 'createConfig'
1011

11-
Apps.Backoffice.Backend.controllers.CoursesGetController:
12-
class: ../../../controllers/CoursesGetController
13-
arguments: ['@Shared.QueryBus']
12+
Apps.Backoffice.Backend.controllers.StatusGetController:
13+
class: ../../../controllers/StatusGetController
14+
arguments: []
15+
16+
Apps.Backoffice.Backend.controllers.CoursesGetController:
17+
class: ../../../controllers/CoursesGetController
18+
arguments: ['@Shared.QueryBus']

0 commit comments

Comments
 (0)