-
Notifications
You must be signed in to change notification settings - Fork 0
/
inversify.config.ts
62 lines (54 loc) · 3.99 KB
/
inversify.config.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
52
53
54
55
56
57
58
59
60
61
62
import "reflect-metadata";
const PouchDB = require('pouchdb');
import {Container} from "inversify";
import {Validator} from "./src/services/validator/Validator";
import TYPES from "./src/container/Types";
import {IValidator} from "./src/services/validator/interface/IValidator";
import {WeatherController} from "./src/http/controllers/WeatherController";
import {MailValidationMiddleware} from "./src/http/middleware/MailValidationMiddleware";
import {CityValidationMiddleware} from "./src/http/middleware/CityValidationMiddleware";
import {BasicValidator} from "./src/services/validator/BasicValidator";
import {ValidationRulesBuilder} from "./src/services/validator/rule/builder/ValidationRulesBuilder";
import Database = PouchDB.Database;
import pdbConfig from './config/pouchdb.conf';
import {RequestHandler} from "./src/services/handler/RequestHandler";
import {PersistingHandler} from "./src/services/handler/request-handler/handlers/PersistingHandler";
import {PouchDBPayloadPersister} from "./src/services/persisters/PouchDBPayloadPersister";
import {IPayloadPersister} from "./src/services/persisters/interface/IPayloadPersister";
import {IHttpClient} from "./src/services/http-client/interface/IHttpClient";
import {AxiosHttpClient} from "./src/services/http-client/AxiosHttpClient";
import axios from 'axios';
import {HttpHandler} from "./src/services/handler/request-handler/handlers/HttpHandler";
import {ConsoleLogHandler} from "./src/services/handler/request-handler/handlers/ConsoleLogHandler";
import {IWeatherService} from "./src/services/weather/interface/IWeatherService";
import {MetaweatherService} from "./src/services/weather/metaweather/MetaweatherService";
import {IWeatherDecorator} from "./src/services/decorator/interface/IWeatherDecorator";
import {WeatherDecorator} from "./src/services/decorator/WeatherDecorator";
const container: Container = new Container();
const validator: IValidator = new Validator();
const basicValidator: BasicValidator = new BasicValidator();
const pouchDB: Database = new PouchDB(pdbConfig.prefix);
container.bind(TYPES.HttpClient.Axios).toConstantValue(axios);
container.bind<Database>(TYPES.Database.PouchDB).toConstantValue(pouchDB);
container.bind<IValidator>(TYPES.Validator.IValidator).toConstantValue(validator).whenTargetIsDefault();
container.bind<IHttpClient>(TYPES.HttpClient.IHttpClient).to(AxiosHttpClient);
container.bind<IValidator>(TYPES.Validator.IValidator).toConstantValue(basicValidator).whenTargetNamed('BasicValidator');
container.bind<IPayloadPersister>(TYPES.Persister.IPayloadPersister).to(PouchDBPayloadPersister);
container.bind<IWeatherService>(TYPES.Weather.IWeatherService).to(MetaweatherService);
container.bind<IWeatherDecorator>(TYPES.Decorator.IWeatherDecorator).to(WeatherDecorator);
container.bind<ValidationRulesBuilder>(TYPES.Validator.RuleBuilder).toDynamicValue(() => {return new ValidationRulesBuilder()});
container.bind<RequestHandler>(TYPES.Handler.RequestHandler.HttpHandler).to(HttpHandler);
container.bind<RequestHandler>(TYPES.Handler.RequestHandler.PersistingHandler).to(PersistingHandler);
container.bind<RequestHandler>(TYPES.Handler.RequestHandler.ConsoleLogHandler).to(ConsoleLogHandler);
container.bind<WeatherController>(TYPES.Controllers.WebsiteController).to(WeatherController);
container.bind<MailValidationMiddleware>(TYPES.Middlewares.MailValidationMiddleware).to(MailValidationMiddleware);
container.bind<CityValidationMiddleware>(TYPES.Middlewares.CityValidationMiddleware).to(CityValidationMiddleware);
container.bind<RequestHandler>(TYPES.Handler.ProxyHandlers).toDynamicValue(() => {
const persistingHandler = container.get<RequestHandler>(TYPES.Handler.RequestHandler.PersistingHandler);
const httpHandler = container.get<RequestHandler>(TYPES.Handler.RequestHandler.HttpHandler);
const consoleLogHandler = container.get<RequestHandler>(TYPES.Handler.RequestHandler.ConsoleLogHandler);
consoleLogHandler.handler = httpHandler;
persistingHandler.handler = consoleLogHandler;
return persistingHandler;
});
export default container;