1- import { Container } from 'inversify'
21import { Db , MongoClient , Collection } from 'mongodb'
32import * as Pino from 'pino'
43import { pick } from 'ramda'
@@ -23,7 +22,6 @@ export interface BatchReaderConfiguration extends LoggingConfiguration, ServiceC
2322export class BatchReader {
2423 private readonly logger : Pino . Logger
2524 private readonly configuration : BatchReaderConfiguration
26- private readonly container = new Container ( )
2725 private mongoClient : MongoClient
2826 private dbConnection : Db
2927 private router : Router
@@ -44,15 +42,48 @@ export class BatchReader {
4442 this . messaging = new Messaging ( this . configuration . rabbitmqUrl , exchangesMessaging )
4543 await this . messaging . start ( )
4644
47- this . initializeContainer ( )
45+ const ipfs = new IPFS ( {
46+ configuration : {
47+ ipfsUrl : this . configuration . ipfsUrl ,
48+ } ,
49+ } )
50+
51+ const directoryCollection = this . dbConnection . collection ( 'batchReader' )
52+
53+ const directoryDAO = new DirectoryDAO ( {
54+ dependencies : {
55+ directoryCollection,
56+ } ,
57+ } )
4858
49- this . router = this . container . get ( 'Router' )
59+ const claimController = new ClaimController ( {
60+ dependencies : {
61+ directoryDAO,
62+ ipfs,
63+ } ,
64+ } )
65+
66+ this . router = new Router ( {
67+ dependencies : {
68+ logger : this . logger ,
69+ messaging : this . messaging ,
70+ claimController,
71+ } ,
72+ exchange : this . configuration . exchanges ,
73+ } )
5074 await this . router . start ( )
5175
52- this . service = this . container . get ( 'Service' )
76+ this . service = new Service ( {
77+ dependencies : {
78+ logger : this . logger ,
79+ messaging : this . messaging ,
80+ } ,
81+ configuration : {
82+ readNextDirectoryIntervalInSeconds : this . configuration . readNextDirectoryIntervalInSeconds ,
83+ } ,
84+ exchange : this . configuration . exchanges ,
85+ } )
5386 await this . service . start ( )
54- const directoryDAO : DirectoryDAO = this . container . get ( 'DirectoryDAO' )
55- await directoryDAO . start ( )
5687
5788 this . logger . info ( 'BatchReader Started' )
5889 }
@@ -64,24 +95,4 @@ export class BatchReader {
6495 await this . router . stop ( )
6596 await this . service . stop ( )
6697 }
67-
68- initializeContainer ( ) {
69- this . container . bind < Pino . Logger > ( 'Logger' ) . toConstantValue ( this . logger )
70- this . container . bind < ClaimController > ( 'ClaimController' ) . to ( ClaimController )
71- this . container . bind < Collection > ( 'directoryCollection' ) . toConstantValue ( this . dbConnection . collection ( 'batchReader' ) )
72- this . container . bind < Db > ( 'DB' ) . toConstantValue ( this . dbConnection )
73- this . container . bind < DirectoryDAO > ( 'DirectoryDAO' ) . to ( DirectoryDAO )
74- this . container . bind < IPFS > ( 'IPFS' ) . to ( IPFS )
75- this . container . bind < IPFSConfiguration > ( 'IPFSConfiguration' ) . toConstantValue ( {
76- ipfsUrl : this . configuration . ipfsUrl ,
77- } )
78- this . container . bind < Router > ( 'Router' ) . to ( Router )
79- this . container . bind < Messaging > ( 'Messaging' ) . toConstantValue ( this . messaging )
80- this . container . bind < Service > ( 'Service' ) . to ( Service )
81- this . container . bind < ServiceConfiguration > ( 'ServiceConfiguration' ) . toConstantValue ( {
82- readNextDirectoryIntervalInSeconds : this . configuration . readNextDirectoryIntervalInSeconds ,
83- } )
84-
85- this . container . bind < ExchangeConfiguration > ( 'ExchangeConfiguration' ) . toConstantValue ( this . configuration . exchanges )
86- }
8798}
0 commit comments