File tree Expand file tree Collapse file tree 5 files changed +34
-16
lines changed
Backoffice/Courses/infrastructure/persistence
Shared/infrastructure/persistence/elasticsearch
apps/backoffice/backend/config/dependency-injection Expand file tree Collapse file tree 5 files changed +34
-16
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
import { Client as ElasticClient } from '@elastic/elasticsearch' ;
2
- import config from '../../../../../apps/backoffice/backend/config/config' ;
3
2
import { Nullable } from '../../../domain/Nullable' ;
3
+ import ElasticConfig from './ElasticConfig' ;
4
4
5
5
export class ElasticClientFactory {
6
6
private static clients : { [ key : string ] : ElasticClient } = { } ;
7
7
8
- static async createClient ( contextName : string ) : Promise < ElasticClient > {
8
+ static async createClient ( contextName : string , config : ElasticConfig ) : Promise < ElasticClient > {
9
9
let client = ElasticClientFactory . getClient ( contextName ) ;
10
10
11
11
if ( ! client ) {
12
- client = await ElasticClientFactory . createAndConnectClient ( ) ;
12
+ client = await ElasticClientFactory . createAndConnectClient ( config ) ;
13
13
14
14
ElasticClientFactory . registerClient ( client , contextName ) ;
15
15
}
@@ -21,8 +21,8 @@ export class ElasticClientFactory {
21
21
return ElasticClientFactory . clients [ contextName ] ;
22
22
}
23
23
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 } ) ;
26
26
27
27
return client ;
28
28
}
Original file line number Diff line number Diff line change
1
+ type ElasticConfig = { url : string } ;
2
+
3
+ export default ElasticConfig ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ services:
13
13
factory :
14
14
class : ../../../../../../Contexts/Shared/infrastructure/persistence/elasticsearch/ElasticClientFactory
15
15
method : ' createClient'
16
- arguments : ['mooc']
16
+ arguments : ['mooc', '@Apps.Backoffice.Backend.ElasticConfig' ]
17
17
18
18
Shared.QueryHandlersInformation :
19
19
class : ../../../../../../Contexts/Shared/infrastructure/QueryBus/QueryHandlersInformation
Original file line number Diff line number Diff line change 1
1
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'
6
6
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'
10
11
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']
You can’t perform that action at this time.
0 commit comments