import { ApplicationInsightsClient , CredentialType , registerAzureServicesToContainer , secretNames , SecretProvider } from 'azure-services' ; import { IoC , setupRuntimeConfigContainer } from 'common' ; import * as inversify from 'inversify' ; import { isNil } from 'lodash' ; import { registerLoggerToContainer } from 'logger' ; import { webApiTypeNames } from './web-api-types' ; let processLifeCycleContainer ; export function getProcessLifeCycleContainer ( ) { if ( isNil ( processLifeCycleContainer ) ) { processLifeCycleContainer = new inversify . Container ( { autoBindInjectable : true } ) ; setupRuntimeConfigContainer ( processLifeCycleContainer ) ; registerLoggerToContainer ( processLifeCycleContainer ) ; registerAzureServicesToContainer ( processLifeCycleContainer , CredentialType . AppService ) ; IoC . setupSingletonProvider < ApplicationInsightsClient > ( webApiTypeNames . ApplicationInsightsClientProvider , processLifeCycleContainer , async ( context ) => { const secretProvider = context . container . get ( SecretProvider ) ; const appInsightsApiKey = await secretProvider . getSecret ( secretNames . appInsightsApiKey ) ; return new ApplicationInsightsClient ( process . env . APPINSIGHTS_APPID , appInsightsApiKey ) ; } ) ; } return processLifeCycleContainer ; }