Created
January 7, 2022 22:35
-
-
Save mlevkovsky/9e3e7e88e4c2d709ab117032c7e7316e to your computer and use it in GitHub Desktop.
main bootstrapping of your dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Container } from 'inversify'; | |
import { TYPE } from 'inversify-restify-utils'; | |
import 'reflect-metadata'; | |
import * as ShopifyToken from 'shopify-token'; | |
import { Connection, ConnectionOptions, createConnection } from 'typeorm'; | |
import { ApiController } from './controllers/ApiController'; | |
import { ApplicationChargeController } from './controllers/ApplicationChargeController'; | |
import { AuthController } from './controllers/AuthController'; | |
import { GpdrController } from './controllers/GpdrController'; | |
import { HealthController } from './controllers/HealthController'; | |
import { MerchantController } from './controllers/MerchantController'; | |
import { NotificationController } from './controllers/NotificationController'; | |
import { ProductController } from './controllers/ProductController'; | |
import { SettingsController } from './controllers/SettingsController'; | |
import { ViewController } from './controllers/ViewController'; | |
import { WebhookController } from './controllers/WebhookController'; | |
import { MerchantGateway } from './gateway/MerchantGateway'; | |
import { ShopifyGateway } from './gateway/ShopifyGateway'; | |
import { ApplicationChargeService } from './services/ApplicationChargeService'; | |
import { CheckoutService } from './services/CheckoutService'; | |
import { GpdrService } from './services/GpdrService'; | |
import { MerchantService } from './services/MerchantService'; | |
import { NotificationService } from './services/NotificationService'; | |
import { OrderService } from './services/OrderService'; | |
import { ProductLoader } from './services/ProductLoader'; | |
import { SettingsService } from './services/SettingsService'; | |
import { ShopifyAuthService } from './services/ShopifyAuthService'; | |
import { StripeService } from './services/StripeService'; | |
import { WebhookService } from './services/WebhookService'; | |
export async function bind(container: Container) { | |
container.bind<HealthController>(TYPE.Controller) | |
.to(HealthController) | |
.whenTargetNamed('HealthController'); | |
container.bind<ProductController>(TYPE.Controller) | |
.to(ProductController) | |
.whenTargetNamed('ProductController'); | |
container.bind<AuthController>(TYPE.Controller) | |
.to(AuthController) | |
.whenTargetNamed('AuthController'); | |
container.bind<NotificationController>(TYPE.Controller) | |
.to(NotificationController) | |
.whenTargetNamed('NotificationController'); | |
container.bind<GpdrController>(TYPE.Controller) | |
.to(GpdrController) | |
.whenTargetNamed('GpdrController'); | |
container.bind<WebhookController>(TYPE.Controller) | |
.to(WebhookController) | |
.whenTargetNamed('WebhookController'); | |
container.bind<MerchantController>(TYPE.Controller) | |
.to(MerchantController) | |
.whenTargetNamed('MerchantController'); | |
container.bind<ApplicationChargeController>(TYPE.Controller) | |
.to(ApplicationChargeController) | |
.whenTargetNamed('ApplicationChargeController'); | |
container.bind<ViewController>(TYPE.Controller) | |
.to(ViewController) | |
.whenTargetNamed('ViewController'); | |
container.bind<SettingsController>(TYPE.Controller) | |
.to(SettingsController) | |
.whenTargetNamed('SettingsController'); | |
container.bind<ApiController>(TYPE.Controller) | |
.to(ApiController) | |
.whenTargetNamed('ApiController'); | |
container.bind('Logger') | |
.toConstantValue( | |
new Rollbar({ | |
accessToken: process.env.ROLLBAR_TOKEN, | |
captureUncaught: true, | |
captureUnhandledRejections: true, | |
}), | |
); | |
container.bind('Cache').toConstantValue(new NodeCache({stdTTL: 600})); | |
container.bind('EmailService') | |
.toConstantValue(new Mailchimp(process.env.MAILCHIMP_API_KEY)); | |
container.bind('Analytics') | |
.toConstantValue(new Analytics(process.env.SEGMENT_KEY)) | |
.whenTargetNamed('Segment'); | |
container.bind<ShopifyToken>('ShopifyToken') | |
.toConstantValue(new ShopifyToken( | |
{ | |
apiKey: process.env.SHOPIFY_API_KEY, | |
redirectUri: process.env.REDIRECT_URI, | |
sharedSecret: process.env.SHOPIFY_SECRET, | |
}, | |
)); | |
container.bind<ShopifyAuthService>('AuthService') | |
.to(ShopifyAuthService) | |
.whenTargetNamed('Shopify'); | |
container.bind<StripeService>('StripeService') | |
.to(StripeService) | |
.inSingletonScope(); | |
container.bind<NotificationService>('NotificationService') | |
.to(NotificationService) | |
.inSingletonScope(); | |
container.bind<MerchantService>('MerchantService') | |
.to(MerchantService) | |
.inSingletonScope(); | |
container.bind<MerchantGateway>('MerchantGateway') | |
.to(ShopifyGateway) | |
.whenTargetNamed('Shopify'); | |
container.bind<ApplicationChargeService>('ApplicationChargeService') | |
.to(ApplicationChargeService) | |
.inSingletonScope(); | |
container.bind<ProductLoader>('ProductLoader') | |
.to(ProductLoader) | |
.inSingletonScope(); | |
container.bind<OrderService>('OrderService') | |
.to(OrderService) | |
.inSingletonScope(); | |
container.bind<CheckoutService>('CheckoutService') | |
.to(CheckoutService) | |
.inSingletonScope(); | |
container.bind<GpdrService>('GpdrService') | |
.to(GpdrService) | |
.inSingletonScope(); | |
container.bind<WebhookService>('WebhookService') | |
.to(WebhookService) | |
.inSingletonScope(); | |
container.bind<SettingsService>('SettingsService') | |
.to(SettingsService) | |
.inSingletonScope(); | |
const connection = await createConnection(getConnection()); | |
container.bind(Connection).toConstantValue(connection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment