Recently, I've been utilizing InversifyJS to manage dependency injection within my TypeScript server. A current challenge I face is the need to inject varying implementations into my code based on the environment in which it is running.
A common situation arises where I must use S3 in a production environment, but opt for a local folder while developing on my personal laptop. While one approach could involve maintaining separate configuration files with container information, loading the container in services using conditionals seems like a messy solution.
Alternatively, I have considered a single configuration file that dynamically configures either implementation based on the environment:
container.bind<IStorageRepository>(SERVICE_IDENTIFIER.STORAGE).to(
(process.env.ENVIRONMENT === 'prod') ? S3StorageRepository : LocalFolderStorageRepository
);
However, this method doesn't sit well with me as managing multiple environments each with unique requirements can quickly become overwhelming.
Do you have any innovative ideas or suggestions to tackle this issue?