1- import { injectable , Container } from 'inversify'
21import { Db , MongoClient , Collection } from 'mongodb'
32import * as Pino from 'pino'
43import { pick } from 'ramda'
@@ -20,11 +19,9 @@ export interface BatchWriterConfiguration extends LoggingConfiguration, ServiceC
2019 readonly exchanges : ExchangeConfiguration
2120}
2221
23- @injectable ( )
2422export class BatchWriter {
2523 private readonly logger : Pino . Logger
2624 private readonly configuration : BatchWriterConfiguration
27- private readonly container = new Container ( )
2825 private mongoClient : MongoClient
2926 private dbConnection : Db
3027 private router : Router
@@ -45,15 +42,48 @@ export class BatchWriter {
4542 this . messaging = new Messaging ( this . configuration . rabbitmqUrl , exchangesMessaging )
4643 await this . messaging . start ( )
4744
48- this . initializeContainer ( )
45+ const ipfs = new IPFS ( {
46+ configuration : {
47+ ipfsUrl : this . configuration . ipfsUrl ,
48+ } ,
49+ } )
50+
51+ const fileCollection : Collection = this . dbConnection . collection ( 'batchWriter' )
52+
53+ const fileDAO = new FileDAO ( {
54+ dependencies : {
55+ fileCollection,
56+ } ,
57+ } )
4958
50- this . router = this . container . get ( 'Router' )
59+ const claimController = new ClaimController ( {
60+ dependencies : {
61+ fileDAO,
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+ } )
5174 await this . router . start ( )
5275
53- 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+ batchCreationIntervalInSeconds : this . configuration . batchCreationIntervalInSeconds ,
83+ } ,
84+ exchange : this . configuration . exchanges ,
85+ } )
5486 await this . service . start ( )
55- const fileDAO : FileDAO = this . container . get ( 'FileDAO' )
56- await fileDAO . start ( )
5787
5888 this . logger . info ( 'Batcher Writer Started' )
5989 }
@@ -65,24 +95,4 @@ export class BatchWriter {
6595 await this . mongoClient . close ( )
6696 await this . router . stop ( )
6797 }
68-
69- initializeContainer ( ) {
70- this . container . bind < Pino . Logger > ( 'Logger' ) . toConstantValue ( this . logger )
71- this . container . bind < ClaimController > ( 'ClaimController' ) . to ( ClaimController )
72- this . container . bind < Db > ( 'DB' ) . toConstantValue ( this . dbConnection )
73- this . container . bind < FileDAO > ( 'FileDAO' ) . to ( FileDAO )
74- this . container . bind < Collection > ( 'fileCollection' ) . toConstantValue ( this . dbConnection . collection ( 'batchWriter' ) )
75- this . container . bind < IPFS > ( 'IPFS' ) . to ( IPFS )
76- this . container . bind < IPFSConfiguration > ( 'IPFSConfiguration' ) . toConstantValue ( {
77- ipfsUrl : this . configuration . ipfsUrl ,
78- } )
79- this . container . bind < Router > ( 'Router' ) . to ( Router )
80- this . container . bind < Messaging > ( 'Messaging' ) . toConstantValue ( this . messaging )
81- this . container . bind < Service > ( 'Service' ) . to ( Service )
82- this . container . bind < ServiceConfiguration > ( 'ServiceConfiguration' ) . toConstantValue ( {
83- batchCreationIntervalInSeconds : this . configuration . batchCreationIntervalInSeconds ,
84- } )
85-
86- this . container . bind < ExchangeConfiguration > ( 'ExchangeConfiguration' ) . toConstantValue ( this . configuration . exchanges )
87- }
8898}
0 commit comments